Reputation: 2104
So I'm new to image processing, and i'm kinda learning emgucv right now.. ..I want to track a Ball with a specific color- orange.. however.. so..what i needed was to threshold, isolate , or binarize (i don't know the right term).. the image to retain a gray image of white and black. the white being the orange colors and black the non-orange.. (sorry if this sounds kinda dumb).. there are however many considerations when binarizing an image... the shadows.. the shades of oranges...
i'm confused as to what is the best function to use.. i've tried the inRange function for Image..
imgProcessed = imgOriginal.InRange(mincolor,maxcolor);
howver,.. i find it slow..and i can't really binarize all of the ball.. (from dark oranges to light oranges).. plus i gotta adjust the values everytime light conditions changes.. are there any ways to get "all" or atleast "most" of the shades of orange? Sorry..newbie here...I'd appreciate any help..code is not necessary..thanks!:D
there are so many functions to use.. HSV.. inrange.. cvthreshold..what are the best waY? will using hsv rather than bgr be faster?
Upvotes: 0
Views: 830
Reputation: 6614
I have done this. I gave up on the OpenCV functions and did the math by hand. Here is my code:
for (i = 0; i < rows; i = i + step)
{
for (j = 0; j < cols; j = j + step)
{
closestprimary = new Bgr(0, 0, 0);
currentcolor = ImageFrame[i, j];
B = (int)currentcolor.Blue;
G = (int)currentcolor.Green;
R = (int)currentcolor.Red;
//hue = atan2(sqr(3) * (G - B), 2 * R - G - B)
hue = ((Math.Atan2(1.732050808 * (double)(G - B), (double)(2 * R - G - B)) * 57.295779513) + 360) % 360; ;
//find closest primary hue (60 degree)
if (hue >= 15 && hue < 50) {
closestprimary = new Bgr(0, 127, 255); } //orange - sorta had to eyeball this one /shrug
ImageFrame[i, j] = closestprimary;//set new color
}
}
Hopefully you can see how the orange hue is between 15 and 50, and can change the numbers to whatever you want to get whatever color you wish.
http://johndyer.name/lab/colorpicker/ helped me in deciding hues. (look at the top number, by the 'H')
Upvotes: 1