calchist函数需要包含头文件

#include <opencv2/imgproc/imgproc.hpp>

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

  1. //! computes the joint dense histogram for a set of images.
  2. CV_EXPORTS void calcHist( const Mat* images, int nimages,
  3. const int* channels, InputArray mask,
  4. OutputArray hist, int dims, const int* histSize,
  5. const float** ranges, bool uniform=true, bool accumulate=false );
  6.  
  7. //! computes the joint sparse histogram for a set of images.
  8. CV_EXPORTS void calcHist( const Mat* images, int nimages,
  9. const int* channels, InputArray mask,
  10. SparseMat& hist, int dims,
  11. const int* histSize, const float** ranges,
  12. bool uniform=true, bool accumulate=false );
  13.  
  14. CV_EXPORTS_W void calcHist( InputArrayOfArrays images,
  15. const vector<int>& channels,
  16. InputArray mask, OutputArray hist,
  17. const vector<int>& histSize,
  18. const vector<float>& ranges,
  19. 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:用来计算直方图

例程:

  1. #include <cv.h>
  2. #include <highgui.h>
  3.  
  4. using namespace cv;
  5.  
  6. int main( int argc, char** argv )
  7. {
  8. Mat src, hsv;
  9. if( argc != || !(src=imread(argv[], )).data )
  10. return -;
  11.  
  12. cvtColor(src, hsv, CV_BGR2HSV);
  13.  
  14. // Quantize the hue to 30 levels
  15. // and the saturation to 32 levels
  16. int hbins = , sbins = ;
  17. int histSize[] = {hbins, sbins};
  18. // hue varies from 0 to 179, see cvtColor
  19. float hranges[] = { , };
  20. // saturation varies from 0 (black-gray-white) to
  21. // 255 (pure spectrum color)
  22. float sranges[] = { , };
  23. const float* ranges[] = { hranges, sranges };
  24. MatND hist;
  25. // we compute the histogram from the 0-th and 1-st channels
  26. int channels[] = {, };
  27.  
  28. calcHist( &hsv, , channels, Mat(), // do not use mask
  29. hist, , histSize, ranges,
  30. true, // the histogram is uniform
  31. false );
  32. double maxVal=;
  33. minMaxLoc(hist, , &maxVal, , );
  34.  
  35. int scale = ;
  36. Mat histImg = Mat::zeros(sbins*scale, hbins*, CV_8UC3);
  37.  
  38. for( int h = ; h < hbins; h++ )
  39. for( int s = ; s < sbins; s++ )
  40. {
  41. float binVal = hist.at<float>(h, s);
  42. int intensity = cvRound(binVal*/maxVal);
  43. rectangle( histImg, Point(h*scale, s*scale),
  44. Point( (h+)*scale - , (s+)*scale - ),
  45. Scalar::all(intensity),
  46. CV_FILLED );
  47. }
  48.  
  49. namedWindow( "Source", );
  50. imshow( "Source", src );
  51.  
  52. namedWindow( "H-S Histogram", );
  53. imshow( "H-S Histogram", histImg );
  54. waitKey();
  55. }

【Opencv】直方图函数 calchist()的更多相关文章

  1. Opencv中直方图函数calcHist

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

  2. opencv2 直方图之calchist函数使用(转)

    OpenCV提供了calcHist函数来计算图像直方图. 其中C++的函数原型如下:void calcHist(const Mat* arrays, int narrays, const int* c ...

  3. opencv直方图该怎么画

    图像直方图是反映图像中像素分布特性的统计表,一般显示如下: 其中横坐标代表的是图像像素的种类,或者说是灰度级,纵坐标代表的是每一级灰度下像素数或者该灰度级下像素数在所有图像总像素数总所占的百分比. 直 ...

  4. opencv直方图均衡化

    #include <iostream> #include "highgui.h" #include "cv.h" #include "cx ...

  5. opencv-6-图像绘制与opencv Line 函数剖析

    opencv-6-图像绘制与opencv Line 函数剖析 opencvc++qt 开始之前 越到后面, 写的越慢, 之前还抽空去看了下 学堂在线那篇文章提供的方法, 博客第一个人评论的我, 想想还 ...

  6. 【记录一个问题】macos下lldb调试opencv的一个程序,出现“failed to load objfile for”错误,并且无法调试进入opencv的函数

    opencv编译使用了Debug版本,打开了BUILD_WITH_DEBUG_INFO=ON选项. 发现问题后,我又在CMAKE_CXX_FLAGS_DEBUG中设置为 -g -ggdb3,在CMAK ...

  7. OPENCV直方图与匹配

    直方图可以用来描述不同的参数和事物,如物体的色彩分布,物体的边缘梯度模版以及目标位置的当前假设的概率分布. 直方图就是对数据进行统计的一种方法,并且将统计值定义到一系列定义好的bin(组距)中,获得一 ...

  8. OpenCV直方图(直方图、直方图均衡,直方图匹配,原理、实现)

    1 直方图 灰度级范围为 \([0,L-1]\) 的数字图像的直方图是离散函数 \(h(r_k) = n_k\) , 其中 \(r_k\) 是第\(k\)级灰度值,\(n_k\) 是图像中灰度为 \( ...

  9. 【麦子学院】OpenCV教程函数总结

    个自带样例. parter 1: No1. adaptiveskindetector.cpp 利用HSV空间的色调信息的皮肤检測,背景不能有太多与肤色相似的颜色.效果不是特别好. No2. bagof ...

随机推荐

  1. Lua学习三----------Lua数据类型

    © 版权声明:本文为博主原创文章,转载请注明出处 Lua数据类型 - Lua是动态类型语言,不需要为变量定义类型,只需要为变量赋值 - Lua有8中基本数据类型:nil.boolean.number. ...

  2. cocos2dx中使用iconv转码(win32,iOS,Android)

    首先贴下环境:Win7 64, NDK r8e, libiconv-1.14, cygwin 一 Win32环境配置 Cocos2D-X自带有win32上的iconv库.仅仅须要配置一下就可以使用. ...

  3. php迭代器模式

    其实就是遍历数组 然后对数组中的元素进行操作 实现iterator接口即可.

  4. go web的简单服务器

    1)简单web服务器: package main import ( "fmt" "net/http" ) func sayHelloName(w http.Re ...

  5. 循序渐进学Python 1 安装与入门

    1 安装 2 使用 2.1 运行程序 3 艺搜参考 by 2013年10月16日 安装 Windows安装版,源码,帮助文档: 使用 打开开始菜单中的Python GUI启动Python解释器: 启动 ...

  6. ssh无密码登陆屌丝指南

    [0]写在前面 由于ssh 实现的是免密码登陆,大致步骤是: 0.1) client通过ssh登陆到server: 0.2) server检查家目录下的.ssh文件, 并发送公钥文件 authoriz ...

  7. WPF自定义搜索框代码分享

    首先下载搜索图标: 控件中的搜索图标下载地址:http://www.easyicon.net/1183666-Search_icon.html 搜索框设计过程比较简单: 1.先定义一个Rectangl ...

  8. EntityFramework走马观花之CRUD(下)

    我在Entity Framework系列文章的CRUD上篇中介绍了EF的数据查询,中篇谈到了EF的数据更新,下篇则聊聊EF实现CRUD的内部原理. 跟踪实体对象状态 在CRUD上篇和中篇谈到,为了实现 ...

  9. jQuery 插件开发(1)

    JavaScript 是一门混乱的语言,好的特性和坏的特性混杂在一起.而不同浏览器对标准的解析不一致,使得这门语言更加混乱,在这种情况下遵循最佳实践有诸多好处,至少不会掉入坑里.所以就有了<Ja ...

  10. 开源Flex Air版免费激情美女视频聊天室,免费网络远程视频会议系统((Flex,Fms3联合打造))

    开源Flex Air版免费激情美女视频聊天室,免费网络远程视频会议系统((Flex,Fms3联合打造))   Flex,Fms3系列文章导航 Flex,Fms3相关文章索引 本篇是视频聊天,会议开发实 ...