Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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; SparseMat hist_base; VideoCapture cam(0); int h_bins = 50; //int s_bins = 32; //int v_bins = 10;

int histSize[] = {h_bins};

float h_ranges[] = { 0, 180 };
//float s_ranges[] = { 0, 256 };
//float v_ranges[] = { 0, 256 };
const float* ranges[] = { h_ranges};
int channels[] = { 0};


if (cam.read(video)) {
    cvtColor(video, video, CV_BGR2HSV_FULL);
    Mat ROI(video,face);
    flip(ROI, ROI, 1);
    deepRoiExplorer =ROI.clone();
    calcHist( &ROI, 1, channels, Mat(), hist_base, 1, histSize, ranges, true, false);
    int scale = 10;
    Mat histImg = Mat::zeros(h_bins*scale,h_bins*10, CV_8UC3);
}


while (cam.read(video)) {
    rectangle(video, face, CV_RGB(128,128,128));
    flip(video,video, 1);
    imshow("video", video);
    imshow("ROI", deepRoiExplorer);
}

}

click to hide/show revision 2
No.2 Revision

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;
SparseMat hist_base;
VideoCapture cam(0);
int h_bins = 50;
//int s_bins = 32;
//int v_bins = 10;

10;
int histSize[] = {h_bins};
 float h_ranges[] = { 0, 180 };
 //float s_ranges[] = { 0, 256 };
 //float v_ranges[] = { 0, 256 };
 const float* ranges[] = { h_ranges};
 int channels[] = { 0};
  if (cam.read(video)) {
 cvtColor(video, video, CV_BGR2HSV_FULL);
 Mat ROI(video,face);
  flip(ROI, ROI, 1);
 deepRoiExplorer =ROI.clone();
  calcHist( &ROI, 1, channels, Mat(), hist_base, 1, histSize, ranges, true, false);
 int scale = 10;
 Mat histImg = Mat::zeros(h_bins*scale,h_bins*10, CV_8UC3);
 }
  while (cam.read(video)) {
 rectangle(video, face, CV_RGB(128,128,128));
 flip(video,video, 1);
 imshow("video", video);
 imshow("ROI", deepRoiExplorer);
 }
}

}

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;
    SparseMat MatND hist_base;
 VideoCapture cam(0);
 int h_bins = 50;
    //int s_bins = 32;
    //int v_bins = 10;

    int histSize[] = {h_bins};
 float h_ranges[] = { 0, 180 };
    //float s_ranges[] = { 0, 256 };
    //float v_ranges[] = { 0, 256 };
    const float* ranges[] = { h_ranges};
    int channels[] = { 0};

     if (cam.read(video)) {
     cvtColor(video, video, CV_BGR2HSV_FULL);
    CV_BGR2HSV);
    Mat ROI(video,face);
     flip(ROI, ROI, 1);
     deepRoiExplorer =ROI.clone();
 }
calcHist( &ROI, &deepRoiExplorer, 1, channels, 0, Mat(), hist_base, 1, histSize, ranges, true, false);
        int scale = 10;
        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 histImg = Mat::zeros(h_bins*scale,h_bins*10, CV_8UC3);
    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 );
}

}