计算直方图1D

来源:互联网 发布:发型设计软件破解版 编辑:程序博客网 时间:2024/05/01 17:22
#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; }



0 0
原创粉丝点击