Drawing histogram of hue channel of picture
Hi guys... This question might be marked as noob question.. I have been struggling with this problem.. I manages to calculate Histogram of a picture, but cannot show/display it ... How do i do that..
This is How i calculated it
void track(Rect face ){
Mat video,deepRoiExplorer;
MatND hist_base;
VideoCapture cam(0);
int h_bins = 50;
int histSize[] = {h_bins};
float h_ranges[] = { 0, 180 };
const float* ranges[] = { h_ranges};
if (cam.read(video)) {
cvtColor(video, video, CV_BGR2HSV);
Mat ROI(video,face);
flip(ROI, ROI, 1);
deepRoiExplorer =ROI.clone();
}
calcHist( &deepRoiExplorer, 1, 0, Mat(), hist_base, 1, histSize, ranges, true, false);
cout << "hello" << endl;
double total;
total = deepRoiExplorer.rows*deepRoiExplorer.cols;
for (int h = 0; h<h_bins; h++) {
float binVal = hist_base.at<float>(h);
cout<<" "<<binVal;
}
int hist_w = 512; int hist_h = 400;
int bin_w = cvRound( (double) hist_w/h_bins );
Mat histImage( hist_h, hist_w, CV_8UC1, Scalar( 0,0,0) );
normalize(hist_base, hist_base, 0, histImage.rows, NORM_MINMAX, -1, Mat() );
for( int i = 1; i < h_bins; i++ )
{
line( histImage, Point( bin_w*(i-1), hist_h - cvRound(hist_base.at<float>(i-1)) ) ,
Point( bin_w*(i), hist_h - cvRound(hist_base.at<float>(i)) ),
Scalar( 255, 0, 0), 2, 8, 0 );
}
while (cam.read(video)) {
rectangle(video, face, CV_RGB(128,128,128));
flip(video,video, 1);
imshow("video", video);
imshow("ROI", deepRoiExplorer);
imshow( "Result", histImage );
}
}
Have you seen this page? Your histogram shall be calculated the same way.
I was able to do RGB but the HSV is causing the problem..
Maybe CV_BGR2HSV_FULL is the problem?
The problem is i cannot imshow the histogram..
Imshow("hist",hist_base) gives out the error message No matching function for call to imshow.
shouldn't be ranges {0, 256}?
histSize
andranges
shouldn't be given as ref (&histSize
and&ranges
)?&ROI
shouldn't be&ROI[0]
? And more, you have just the values inhist_base
.I changed it above.. But now i am not able to calc. the histogram...