Quantcast
Channel: OpenCV Q&A Forum - Latest question feed
Viewing all articles
Browse latest Browse all 19555

How to draw histogram

$
0
0
Hi, How do i draw a histogram like the one in matlab ? http://www.mathworks.com/help/matlab/ref/histogram.html Is there a code with a few lines that draws a nice histogram like the one in matlab ? I have been stuck for days. Please help !!! http://docs.opencv.org/2.4/doc/tutorials/imgproc/histograms/histogram_calculation/histogram_calculation.html is ugly as shit. IplImage* DrawHistogram(CvHistogram *hist, float scaleX = 1, float scaleY = 1) { float histMax = 0; cvGetMinMaxHistValue(hist, 0, &histMax, 0, 0); IplImage* imgHist = cvCreateImage(cvSize(256 * scaleX, 64 * scaleY), 8, 1); cvZero(imgHist); for (int i = 0; i<255; i++) { float histValue = *(hist->mat.data.ptr + i); float nextValue = *(hist->mat.data.ptr + 1 + i); CvPoint pt1 = cvPoint(i*scaleX, 64 * scaleY); CvPoint pt2 = cvPoint(i*scaleX + scaleX, 64 * scaleY); CvPoint pt3 = cvPoint(i*scaleX + scaleX, (64 - nextValue * 64 / histMax)*scaleY); CvPoint pt4 = cvPoint(i*scaleX, (64 - histValue * 64 / histMax)*scaleY); int numPts = 5; CvPoint pts[] = { pt1, pt2, pt3, pt4, pt1 }; cvFillConvexPoly(imgHist, pts, numPts, cvScalar(255)); } return imgHist; } or also tell me how to export histogram data type to matlab so i can plot it there and not in OpenShittyCV

Viewing all articles
Browse latest Browse all 19555

Trending Articles