I am creating a hsv histogram from an image like below.
- (void)processImageWithHsv:(Mat&)image;
{
Mat image_hsv;
cvtColor(image, image_hsv, CV_BGR2HSV);
int hbins = 50, sbins = 60;
int histSize[] = {hbins, sbins};
float hranges[] = { 0, 360 };
float sranges[] = { 0, 256 };
const float* ranges[] = { hranges, sranges };
MatND hist;
int channels[] = {0, 1};
calcHist( &image_hsv, 1, channels, Mat(), // do not use mask
hist, 2, histSize, ranges,
true, // the histogram is uniform
false );
double maxVal = 0;
minMaxLoc(hist, 0, &maxVal, 0, 0);
// ???: HOW Convert this information to colour value
}
But I have no idea to get most dominant color value from that hist
?
Should I use maxVal
?
You made some mistakes:
value
but you tellcalcHist
to work with hue and saturation. You should change channels.hranges
is wrong: it should be 180.dims
should be 1 (not 2), because you only need thevalue
histogram.After those correction
maxVal
should contain the most recurringvalue
value.