从HSV直方图中获取主要颜色值 [英] Getting dominant colour value from HSV Histogram

查看:108
本文介绍了从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?

推荐答案

您犯了一些错误:

  1. 您正在寻找主色value,但您告诉calcHist使用色相和饱和度.您应该更改频道.
  2. 您的hranges是错误的:应该为180.
  3. dims应该为1(而不是2),因为您只需要value直方图.
  1. You are looking for dominant color value but you tell calcHist to work with hue and saturation. You should change channels.
  2. Your hranges is wrong: it should be 180.
  3. dims should be 1 (not 2), because you only need the value histogram.

在进行了更正后,maxVal应该包含重复出现的value值.

After those correction maxVal should contain the most recurring value value.

这篇关于从HSV直方图中获取主要颜色值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆