2011-04-17 91 views

回答

0

您可以使用直方圖來查找顏色分佈並選擇最高值作爲主色。目前不知道Emgu CV的相關功能。好運

1

您應該首先獲取每個顏色通道的直方圖。然後你可以使用minmax函數來獲得最主要的顏色。

我發佈的代碼是針對HSV圖像的,您可以更改您的色彩空間的通道名稱。

Image<Gray, Byte>[] channels = hsv1.Split(); 
       Image<Gray, Byte> ImgHue = channels[0]; 
       Image<Gray, Byte> ImgSat = channels[1]; 
       Image<Gray, Byte> ImgVal = channels[2]; 

DenseHistogram histo1 = new DenseHistogram(255, new RangeF(0, 255)); 

histo1.Calculate<byte>(new Image<Gray, byte>[] { ImgHue }, true, null); 

    float minV, maxV; 
     int[] minL; 
     int[] maxL; 


histo1.MinMax(out minV, out maxV, out minL, out maxL); 


string mystr = Convert.ToString(maxL[0]); 
       label1.Text = "Hue= " + mystr; 

您也可以對飽和度和值通道做同樣的事情。