Return to Snippet

Revision: 31676
at September 10, 2010 13:28 by browny


Updated Code
#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);

Revision: 31675
at September 10, 2010 13:25 by browny


Initial Code
#include <vector>
#include <algorithm>
#include <numeric>
#include <iterator>

vector<int> hist(256, 0);

// fill 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);

Initial URL
http://blog.isaias.com.mx/2005/12/1d-histogram-with-opencv-c.html

Initial Description
繪製 1D vector 成  1D Histogram

Initial Title
[OpenCV] Draw 1D Histogram Graph

Initial Tags

                                

Initial Language
C++