当前位置:   article > 正文

计算直方图1D_histogram1d

histogram1d
  1. #ifndef HISTOGRAM_H_
  2. #define HISTOGRAM_H_
  3. #include <opencv2/core/core.hpp>
  4. #include <opencv2/highgui/highgui.hpp>
  5. #include <opencv2/imgproc/imgproc.hpp>
  6. #include <iostream>
  7. #include <vector>
  8. #include<opencv2/core/core.hpp>
  9. #include<opencv2/highgui/highgui.hpp>
  10. #include<opencv2/imgproc/imgproc.hpp>
  11. #include<iostream>
  12. #include <vector>
  13. using namespace std;
  14. using namespace cv;
  15. class Histogram1D
  16. {
  17. private:
  18. int histSize[1];
  19. float hranges[2];
  20. const float *ranges[1];
  21. int channels[1];
  22. public:
  23. Histogram1D()
  24. {
  25. histSize[0]=256;
  26. hranges[0]=0.0;
  27. hranges[1]=255.0;
  28. ranges[0]=hranges;
  29. channels[0]=0;
  30. };
  31. cv::MatND getHistogram(const cv::Mat &image)
  32. {
  33. cv::MatND hist;
  34. cv::calcHist(&image,1,channels,cv::Mat(),hist,1,histSize,ranges);
  35. return hist;
  36. };
  37. };
  38. #endif /* HISTOGRAM_H_ */
  39. #include"Histogram1D.h"
  40. int main()
  41. {
  42. cv::Mat image=cv::imread("d:\\test\\opencv\\group.jpg",0);
  43. if( !image.data ) exit(0);
  44. Histogram1D h;
  45. cv::MatND histo=h.getHistogram(image);
  46. for(int i=0;i<256;i++)
  47. cout<<"value"<<i<<"="<<histo.at<float>(i)<<endl;
  48. getchar();
  49. return 0;
  50. }



声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/141089
推荐阅读
相关标签
  

闽ICP备14008679号