calchist函数需要包含头文件

#include <opencv2/imgproc/imgproc.hpp>

函数声明(三个重载 calchist函数):

//! computes the joint dense histogram for a set of images.
CV_EXPORTS void calcHist( const Mat* images, int nimages,const int* channels, InputArray mask,OutputArray hist, int dims, const int* histSize,const float** ranges, bool uniform=true, bool accumulate=false );//! computes the joint sparse histogram for a set of images.
CV_EXPORTS void calcHist( const Mat* images, int nimages,const int* channels, InputArray mask,SparseMat& hist, int dims,const int* histSize, const float** ranges,bool uniform=true, bool accumulate=false );CV_EXPORTS_W void calcHist( InputArrayOfArrays images,const vector<int>& channels,InputArray mask, OutputArray hist,const vector<int>& histSize,const vector<float>& ranges,bool accumulate=false );

官方文档:

The functions calcHist calculate the histogram of one or more arrays. The elements of a tuple used to increment a histogram bin are taken from the corresponding input arrays at the same location. The sample below shows how to compute a 2D Hue-Saturation histogram for a color image.

Parameters:
  • images – Source arrays. They all should have the same depth, CV_8U or CV_32F , and the same size. Each of them can have an arbitrary number of channels.
  • nimages – Number of source images.
  • channels – List of the dims channels used to compute the histogram. The first array channels are numerated from 0 to images[0].channels()-1 , the second array channels are counted from images[0].channels() to images[0].channels() + images[1].channels()-1, and so on.
  • mask – Optional mask. If the matrix is not empty, it must be an 8-bit array of the same size as images[i] . The non-zero mask elements mark the array elements counted in the histogram.
  • hist – Output histogram, which is a dense or sparse dims -dimensional array.
  • dims – Histogram dimensionality that must be positive and not greater than CV_MAX_DIMS (equal to 32 in the current OpenCV version).
  • histSize – Array of histogram sizes in each dimension.
  • ranges – Array of the dims arrays of the histogram bin boundaries in each dimension. When the histogram is uniform ( uniform =true), then for each dimension i it is enough to specify the lower (inclusive) boundary  of the 0-th histogram bin and the upper (exclusive) boundary  for the last histogram bin histSize[i]-1 . That is, in case of a uniform histogram each of ranges[i] is an array of 2 elements. When the histogram is not uniform ( uniform=false ), then each of ranges[i] contains histSize[i]+1 elements: . The array elements, that are not between  and  , are not counted in the histogram.
  • uniform – Flag indicating whether the histogram is uniform or not (see above).
  • accumulate – Accumulation flag. If it is set, the histogram is not cleared in the beginning when it is allocated. This feature enables you to compute a single histogram from several sets of arrays, or to update the histogram in time.

释义:

images:源图像矩阵(可以多个,但必须满足一定条件:同等深度,同等大小,同种数据类型:CV_8U或CV_32F,通道数不需要一致)

nimages:源图像个数

channels:用来计算直方图

例程:

#include <cv.h>
#include <highgui.h>using namespace cv;int main( int argc, char** argv )
{Mat src, hsv;if( argc != 2 || !(src=imread(argv[1], 1)).data )return -1;cvtColor(src, hsv, CV_BGR2HSV);// Quantize the hue to 30 levels// and the saturation to 32 levelsint hbins = 30, sbins = 32;int histSize[] = {hbins, sbins};// hue varies from 0 to 179, see cvtColorfloat hranges[] = { 0, 180 };// saturation varies from 0 (black-gray-white) to// 255 (pure spectrum color)float sranges[] = { 0, 256 };const float* ranges[] = { hranges, sranges };MatND hist;// we compute the histogram from the 0-th and 1-st channelsint channels[] = {0, 1};calcHist( &hsv, 1, channels, Mat(), // do not use maskhist, 2, histSize, ranges,true, // the histogram is uniformfalse );double maxVal=0;minMaxLoc(hist, 0, &maxVal, 0, 0);int scale = 10;Mat histImg = Mat::zeros(sbins*scale, hbins*10, CV_8UC3);for( int h = 0; h < hbins; h++ )for( int s = 0; s < sbins; s++ ){float binVal = hist.at<float>(h, s);int intensity = cvRound(binVal*255/maxVal);rectangle( histImg, Point(h*scale, s*scale),Point( (h+1)*scale - 1, (s+1)*scale - 1),Scalar::all(intensity),CV_FILLED );}namedWindow( "Source", 1 );imshow( "Source", src );namedWindow( "H-S Histogram", 1 );imshow( "H-S Histogram", histImg );waitKey();
}

转载于:https://www.cnblogs.com/Atanisi/p/6910125.html

【Opencv】直方图函数 calchist()相关推荐

  1. Opencv中直方图函数calcHist

    Opencv中直方图函数calcHist calcHist函数在Opencv中是极难理解的一个函数,一方面是参数说明晦涩难懂,另一方面,说明书给出的实例也不足以令人完全搞清楚该函数的使用方式.最难理解 ...

  2. OpenCV使用函数calcHist的实例(附完整代码)

    OpenCV使用函数calcHist的实例 OpenCV使用函数calcHist的实例 OpenCV使用函数calcHist的实例 #include "opencv2/highgui.hpp ...

  3. 23 OpenCV直方图计算calcHist

    一.直方图 图像直方图是基于图像像素值,其实对图像梯度.每个像素的角度.等一切图像的属性值,我们都可以建立直方图.直方图最常见的几个属性: dims: 需要统计的特征的数据 bins:每个特征空间子区 ...

  4. 【opencv学习笔记】025之直方图计算 - calcHist函数详解

    前言 如果你想了解更多有关于计算机视觉.OpenCV.机器学习.深度学习等相关技术的内容,想与更多大佬一起沟通,那就扫描下方二维码加入我们吧! 1.calcHist函数是干什么滴? 这个问题嘛,看看标 ...

  5. 【拜小白opencv】45-二维H-S直方图绘制----calcHist()函数、minMaxLoc()函数

    常言道"温故而知新",写此文章就是对自己目前学习内容的小小的总结与记录. 本文力求用最简洁的语言,详细的代码将此部分内容讲解清楚,但由于博主同样是刚刚接触OpenCV,或许表达上有 ...

  6. 详解为什么OpenCV的直方图计算函数calcHist()计算出的灰度值为255的像素个数为0

    在使用OpenCV的直方图计算函数calcHist()时,发现灰度值为255的像素个数总是为0. 哪怕图像中灰度值为255的像素个数不为0,使用OpenCV的直方图计算函数calcHist()计算出的 ...

  7. Opencv calcHist 直方图函数

    直方图是对图像像素的统计分布,它统计了每个像素(0到L-1)的数量. 直方图均衡化就是将原始的直方图拉伸,使之均匀分布在全部灰度范围内,从而增强图像的对比度. 直方图均衡化的中心思想是把原始图像的的灰 ...

  8. OpenCV深入学习(5)--直方图之calcHist使用

    这次再深入学习一下calcHist函数,即用于计算直方图的函数,主要是分析一下该函数的众多的参数,看看应该如何使用,先给出一段代码,其中包括两部分,一部分来自opencv_tutorials中的例子, ...

  9. OpenCV-Python直方图计算calcHist函数详解

    ☞ ░ 前往老猿Python博文目录 https://blog.csdn.net/LaoYuanPython ░ 一.引言 在<<数字图像处理>第三章学习总结感悟2:直方图处理: h ...

最新文章

  1. css如何设置dialog,css-dialog提示
  2. 华为北大等联手打造的Transformer竟在CV领域超过了CNN:多项底层视觉任务达到SOTA...
  3. Redfield.Sketch.Master中文版
  4. Entity Framework 6以Code First方式搭建Sqlite数据库环境
  5. JDBC连接数据库经验集萃
  6. 也读《人月神话》:没有银弹的软件工程
  7. 服务器硬件oid,HPE ProLiant DL580 Gen10 服务器
  8. 自然语言处理实践Task4
  9. linux的locate工具,linux文本查找工具之locate、find
  10. Appium环境搭建(Java版本)
  11. Kotlin教程 - 收藏集 - 掘金
  12. 绿色版Tomcat的配置
  13. IEEE1588精确网络时钟同步协议简介
  14. 快速明白ARCore + 上手
  15. jdk8 lambda
  16. gaussdb 日常运维命令总结【01】
  17. 玩转Python飞机大战项目
  18. 阿里天池大数据之移动推荐算法大赛总结及代码全公布
  19. 煤矿用计算机,煤矿安全生产中计算机的运用
  20. 单细胞转录组学应用:骨髓微环境

热门文章

  1. 使用Maven打包生成的-SNAPSHOT.jar与-RELEASE.jar分别代表什么?SNAPSHOT是什么意思?RELEASE是什么意思?
  2. 悲催的跨平台文献管理能力
  3. python中的match和search的区别
  4. 语音识别(ASR)评估指标-WER(字错误率)和SER(句错误率)
  5. pycharm连接远程服务器并进行代码上传+远程调试
  6. LeetCode简单题之和为零的N个唯一整数
  7. LeetCode简单题之七进制数
  8. MySQL最新版8.0.21安装配置教程~
  9. 开源软硬一体OpenCV AI Kit(OAK)
  10. 通过Mellanox ConnectX NIC使用XDP加速