Ask Your Question

Understanding the official histogram tutorial

asked 2012-10-18 03:43:38 -0500

Faraz gravatar image

updated 2018-12-19 13:05:58 -0500


Im following the online documentation of opencv 2.4 to learn it. I am at histogram calculation and found a section that was not commented and not explained at all.

The section I am talking about is point number 5, which I have pasted below:

// Draw the histograms for R, G and B
int hist_w = 512; int hist_h = 400;
int bin_w = cvRound( (double) hist_w/histSize );

Mat histImage( hist_h, hist_w, CV_8UC3, Scalar( 0,0,0) );

The tutorial does not state what hist_w and hist_h are and why are they given these values? Also why was a circle detecting function (cvRound) used here and no comment on its function.

Can some one please address these issues, I have spent way too long on the histogram section.

Thank you

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2012-10-18 04:05:22 -0500

Ben gravatar image

updated 2012-10-18 04:07:08 -0500

The code section you pasted here has absolutely nothing to do with histogram computation. Nor does cvRound have anything to do with circle detection.

The code is not explained, because it is pretty self-explanatory. Maybe you should consider having a look at the OpenCV reference to find out, what cvRound actually does. Seriously... did you think the method would detect a circle within a double???

Mat histImage is just an image (as one could suggest from the variable name), which is used to display the histogram. Have a look again at the reference (notably at the Mat constructors). You should be able to find out, what hist_w and hist_h might signify.

edit flag offensive delete link more


Yes sorry, I had mistaken the cvRound function for the void Circle() function.. dont know why.. That was the reason I did not understand it. You are right about the histimage and it is a declaration of a function later used in the line function.. Also you did not have to be so harsh, as I was saying I am learning this and its normal for me to confuse two functions..

Faraz gravatar imageFaraz ( 2012-10-18 17:20:15 -0500 )edit
Login/Signup to Answer

Question Tools


Asked: 2012-10-18 03:43:38 -0500

Seen: 277 times

Last updated: Oct 18 '12