/ Published in: C++
繪製 1D vector æˆ 1D Histogram
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#include <vector> #include <algorithm> #include <numeric> #include <iterator> vector<int> hist(256, 0); // fill data values into hist ... // Plot 1D Histogram IplImage* imgHistogram = cvCreateImage(cvSize(256, 50), 8, 1); cvRectangle(imgHistogram, cvPoint(0,0),cvPoint(256,50),CV_RGB(255,255,255),-1); int max_value = *(max_element(hist.begin(), hist.end())); for (int i = 0; i < 256; ++i) { int val = hist[i]; int nor = cvRound(val * 50 / max_value); cvLine(imgHistogram, cvPoint(i, 50), cvPoint(i, 50-nor), CV_RGB(0,0,0)); } cvShowImage("hist", imgHistogram); cvReleaseImage(&imgHistogram);
URL: http://blog.isaias.com.mx/2005/12/1d-histogram-with-opencv-c.html