赞
踩
- #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;
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。