计算直方图1D

#ifndef HISTOGRAM_H_
#define HISTOGRAM_H_
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
#include <vector>

#include<opencv2/core/core.hpp>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/imgproc/imgproc.hpp>
#include<iostream>
#include <vector>
 using namespace std;
 using namespace cv;
  
 class Histogram1D
 {
 private:
	 int histSize[1];
	 float hranges[2];
	 const float *ranges[1];
	 int channels[1];
 public:
	 Histogram1D()
	 {
		 histSize[0]=256;
		 hranges[0]=0.0;
		 hranges[1]=255.0;
		 ranges[0]=hranges;
		 channels[0]=0;
	 };
	 cv::MatND getHistogram(const cv::Mat &image)
	 {
		 cv::MatND hist;
		 cv::calcHist(&image,1,channels,cv::Mat(),hist,1,histSize,ranges);
		 return hist;
	 };
 };

#endif /* HISTOGRAM_H_ */

#include"Histogram1D.h"
 
 int main()
 {
	 cv::Mat image=cv::imread("d:\\test\\opencv\\group.jpg",0);
	 if( !image.data ) exit(0);
	 Histogram1D h;
	 cv::MatND histo=h.getHistogram(image);
	 for(int i=0;i<256;i++)
		 cout<<"value"<<i<<"="<<histo.at<float>(i)<<endl;
	getchar();
	 return 0;
 }


计算直方图1D_第1张图片

你可能感兴趣的:(C++,opencv,直方图,opencv2)