本文介绍了从HSV直方图中获取主要颜色值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在从下面的图像创建hsv直方图.
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
}
但是我不知道要从那个hist
中获得最主要的颜色值吗?我应该使用maxVal
吗?
But I have no idea to get most dominant color value from that hist
?Should I use maxVal
?
推荐答案
您犯了一些错误:
- 您正在寻找主色
value
,但您告诉calcHist
使用色相和饱和度.您应该更改频道. - 您的
hranges
是错误的:应该为180. -
dims
应该为1(而不是2),因为您只需要value
直方图.
- You are looking for dominant color
value
but you tellcalcHist
to work with hue and saturation. You should change channels. - Your
hranges
is wrong: it should be 180. dims
should be 1 (not 2), because you only need thevalue
histogram.
在进行了更正后,maxVal
应该包含重复出现的value
值.
After those correction maxVal
should contain the most recurring value
value.
这篇关于从HSV直方图中获取主要颜色值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!