简体   繁体   中英

EmguCV Colour Recognition

I'm trying to make a program to detect colours off of a Rubiks cube

thats the screenshot of what I have up and running so far, I basically used the code from the Edge Detection example that ships with emguCV and used that to detect the small cubes (but as you can see some of the small cubes arent being detected, but thats not the problem I want to discuss here).

Now after finding out WHERE the small cubes are, I want to detect which colour they are, currently I'm using the HSV values to decide the colour, like so:

if (current_colour.Hue > 120 && current_colour.Hue < 170)
{
     Colours[(int)colornames.W]++;
}
else if (current_colour.Hue > (170))
{
     Colours[(int)colornames.R]++;
}
else if (current_colour.Hue > 5 && current_colour.Hue < 20 )
{
     Colours[(int)colornames.O]++;
}
else if (current_colour.Hue > 47 && current_colour.Hue< 60)
{
     Colours[(int)colornames.G]++;
}
else if (current_colour.Hue > 15 && current_colour.Hue < 30)
{
     Colours[(int)colornames.Y]++;
}
else if (current_colour.Hue > 100 && current_colour.Hue < 110)
{
     Colours[(int)colornames.B]++;
}

where the values for each colour I got from trial and error using photoshop...I am sure there must be some better way as Im getting results that are jumbled up (especially with the white and red) Any help?

If your image is as simple as your example, You can do a histogram on the image. The peaks in your histogram will correspond to the colors you use.

So you'd have to make a histogram or three, take the highest 10 (or whatever) bin values that are significantly far enough away from each other, and there you have your colors.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM