【opencv】Mat数据直方图计算函数
来源:互联网 发布:天网maze类似软件 编辑:程序博客网 时间:2024/05/04 19:01
Mat calcHistogramsImage(Mat src, int &valMax){int nChannel = src.channels();valMax = 0;if (nChannel == 1){/// Establish the number of binsint histSize = 256;/// Set the ranges ( for B,G,R) )float range[] = { 0, 256 } ;const float* histRange = { range };bool uniform = true;bool accumulate = false;Mat hist;/// Compute the histograms:calcHist( &src, 1, 0, Mat(), hist, 1, &histSize, &histRange, uniform, accumulate );// Draw the histograms for B, G and Rint hist_w = 512; int hist_h = 400;int bin_w = cvRound( (double) hist_w/histSize );Mat histImage( hist_h, hist_w, CV_8UC3, Scalar( 0,0,0) );/// Normalize the result to [ 0, histImage.rows ]normalize(hist, hist, 0, histImage.rows, NORM_MINMAX, -1, Mat() );Mat lineImg(10, hist_w, CV_8UC3, Scalar( 0,0,0) );line(lineImg,Point(0,1),Point(hist_w,1),Scalar( 255, 255, 255),1);int step = 10;int bin = hist_w/step;for (int i=0;i<bin;i++){line(lineImg,Point(10*i,0),Point(10*i,10),Scalar( 255, 255, 255),1);if (i%4 ==0){line(lineImg,Point(10*i,0),Point(10*i,10),Scalar(255 , 255, 255),2);}else{line(lineImg,Point(10*i,0),Point(10*i,10),Scalar( 100, 100, 100),1);}}line(lineImg,Point(200,0),Point(200,10),Scalar( 255, 255, 255),6);line(lineImg,Point(400,0),Point(400,10),Scalar( 255, 255, 255),6);float val_tmp = 0;valMax = 0;for( int i = 1; i < histSize; i++ ){if (hist.at<float>(i) >val_tmp){val_tmp = hist.at<float>(i);valMax = i;}}/// Draw for each channelfor( int i = 1; i < histSize; i++ ){line( histImage, Point( bin_w*(i-1), hist_h - cvRound(hist.at<float>(i-1))) ,Point( bin_w*(i), hist_h - cvRound(hist.at<float>(i)) ),Scalar( 255, 255, 255), 1, 8, 0 );}Mat showM;showM.push_back(histImage);showM.push_back(lineImg);return showM;}else if (nChannel ==3){/// Separate the image in 3 places ( B, G and R )vector<Mat> bgr_planes;split( src, bgr_planes );/// Establish the number of binsint histSize = 256;/// Set the ranges ( for B,G,R) )float range[] = { 0, 256 } ;const float* histRange = { range };bool uniform = true; bool accumulate = false;Mat b_hist, g_hist, r_hist;/// Compute the histograms:calcHist( &bgr_planes[0], 1, 0, Mat(), b_hist, 1, &histSize, &histRange, uniform, accumulate );calcHist( &bgr_planes[1], 1, 0, Mat(), g_hist, 1, &histSize, &histRange, uniform, accumulate );calcHist( &bgr_planes[2], 1, 0, Mat(), r_hist, 1, &histSize, &histRange, uniform, accumulate );// Draw the histograms for B, G and Rint hist_w = 512; int hist_h = 400;int bin_w = cvRound( (double) hist_w/histSize );Mat histImage( hist_h, hist_w, CV_8UC3, Scalar( 0,0,0) );/// Normalize the result to [ 0, histImage.rows ]normalize(b_hist, b_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat() );normalize(g_hist, g_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat() );normalize(r_hist, r_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat() );/// Draw for each channelfor( int i = 1; i < histSize; i++ ){line( histImage, Point( bin_w*(i-1), hist_h - cvRound(b_hist.at<float>(i-1)) ) ,Point( bin_w*(i), hist_h - cvRound(b_hist.at<float>(i)) ),Scalar( 255, 0, 0), 1, 8, 0 );line( histImage, Point( bin_w*(i-1), hist_h - cvRound(g_hist.at<float>(i-1)) ) ,Point( bin_w*(i), hist_h - cvRound(g_hist.at<float>(i)) ),Scalar( 0, 255, 0), 1, 8, 0 );line( histImage, Point( bin_w*(i-1), hist_h - cvRound(r_hist.at<float>(i-1)) ) ,Point( bin_w*(i), hist_h - cvRound(r_hist.at<float>(i)) ),Scalar( 0, 0, 255), 1, 8, 0 );}return histImage;}else{return Mat();}}
0 0
- 【opencv】Mat数据直方图计算函数
- Opencv中的Mat类型常用函数数据
- 【OpenCV】直方图计算
- OpenCV 计算二维直方图
- opencv计算直方图
- opencv 计算直方图 calcHist()
- opencv c++函数 imgproc模块 16 直方图计算
- OpenCV 直方图计算函数 calcHist源码深度剖析
- opencv Mat 图像数据元素进行排序 、常见Mat数据元素统计计算
- openCV直方图相关函数
- 【opencv】Mat 数据操作
- opencv MAT数据操作
- opencv Mat() 构造函数
- OpenCV中的Mat函数
- Opencv之直方图计算calcHist
- opencv 3.0 直方图的计算
- calcHist()计算图像直方图opencv
- 【opencv练习28 - 直方图计算】
- hive 创建/删除/截断 表(翻译自Hive wiki)
- Yii2-admin RBAC权限管理的实现
- 【测试实验】stm32 usart 前导符,空闲符号,断开符号
- log4cpp 封装
- Game of Diamond
- 【opencv】Mat数据直方图计算函数
- 在linux或者unix操作系统中在系统的引导的时候会开启很多服务,这些服务就叫做守护进程。守护进程是在后台运行不与任何控制终端关联,是Linux中的后台服务进程。它是一个生存期较长的进程,通常独立于
- A MST Problem
- Android实现推送方式解决方案
- 直接插入排序与直接选择排序
- Sublime插件开发伊始
- MySQL批量去掉某一个字段特定的值
- 解决AD 不能打开DDB文件的解决方案
- uilabel 详解