opencv 二维直方图
2015-07-19 21:51
330 查看
#define cvCvtPixToPlane cvSplit #define cvCvtPlaneToPix cvMerge
void hist_2D(void) { IplImage *src=cvLoadImage("lena.jpg"); IplImage *hsv=cvCreateImage(cvGetSize(src), IPL_DEPTH_8U, 3); cvCvtColor(src, hsv, CV_BGR2HSV_FULL); IplImage *h_plane=cvCreateImage(cvGetSize(src), IPL_DEPTH_8U, 1); IplImage *s_plane=cvCreateImage(cvGetSize(src), IPL_DEPTH_8U, 1); IplImage *v_plane=cvCreateImage(cvGetSize(src), IPL_DEPTH_8U, 1); IplImage *planes[]={h_plane, s_plane}; cvCvtPixToPlane(hsv, h_plane, s_plane, v_plane, 0); //Build the histogram and compute its contents. int h_bins=256, s_bins=256; CvHistogram *hist; { int hist_size[]={h_bins, s_bins}; float h_ranges[]={0, 255}; //hue is [0, 180] float s_ranges[]={0, 255}; float* ranges[]={h_ranges, s_ranges}; hist=cvCreateHist(2, hist_size, CV_HIST_ARRAY, ranges, 1); } cvCalcHist(planes, hist, 0, 0); //Compute histogram cvNormalizeHist(hist, 1.0); //Normalize it //Create an image to use to visualize our histogram int scale=2; IplImage *hist_img=cvCreateImage(cvSize(h_bins*scale, s_bins*scale), IPL_DEPTH_8U, 3); cvZero(hist_img); //populate our visualization with little gray squares. float max_value=0; cvGetMinMaxHistValue(hist, 0, &max_value, 0, 0); for (int h=0; h<h_bins; h++) { for (int s=0; s<s_bins; s++) { float bin_val=cvQueryHistValue_2D(hist, h, s); int intensity=cvRound(bin_val*255/max_value); cvRectangle(hist_img, cvPoint(h*scale, s*scale), cvPoint((h+1)*scale-1, (s+1)*scale-1), CV_RGB(intensity, intensity, intensity), CV_FILLED); } } cvNamedWindow("Source"); cvShowImage("Source", src); cvNamedWindow("H-S Histogram"); cvShowImage("H-S Histogram", hist_img); cvWaitKey(0); }
相关文章推荐
- linux之LAMP架构优化
- Error reading ComComboBox1->Comproperty;Registry error(win error code;2)
- linux之LAMP架构搭建
- linux c 操作utmp 和 wtmp 文件接口
- openSUSE下安装chrome浏览器,并解决无法全屏的问题
- linux命令4 find、三个时间属性、硬链接和软连接、用户名和密码文件、增加和删除用户组、usermod、su、sudo
- 2.1 linux文件系统相关函数
- Linux内存池技术
- 启动Tomcat报错——Eclipse Removing obsolete files from server
- linux常用命令2 chmod、chown
- linux常用命令1cd、ls、快捷键、mkdir、rmdir、rm、cp、mv、cat等
- NSRunLoop扩展阅读
- linux无线网卡驱动安装
- linux的单用户模式与救援模式
- linux运行级别
- emulator: ERROR: Could not initialize OpenglES emulation, use '-gpu off' to disable it.
- LINUX内核升级-更新网卡驱动
- Hadoop的第一个程序 wordcount
- linux常用的命令
- CentOS 6.5下PXE+Kickstart无人值守安装操作系统