6

Using opencv, can a detection of a certain colour(Between a certain range of rgb values) be carried out in an image or a video frame?

3 Answers 3

3

You need to the define the treshold in RGB, and process the pixels in the image (hopefully not the whole image but a smaller region of interest, maybe a moving foreground shape) that fit to the deffinition. Something similar to what is discussed here.

I am understanding that you know the color(or colors) you want to detect a priori.

I hope this helps.

Sign up to request clarification or add additional context in comments.

2 Comments

thanks for the advice. that could work. what i am trying to do is determine which player is taking their shot in a snooker match. Each player will have a different piece of colored tape on the snooker cue. the tape will be an unusual color. i am trying to detect this unusual color so i can say if player 1 or 2 is at the table?
i am going to make the tape colours unique to the image. so the snooker table will fit the screen. there will be green(obviously) and then the colours of the balls. i will prob pick purple and and light green. so i will threshold for purple, if no match, threshold for light green. this will determine who is at the table hopefully. does this sound feesible to you?
3

Yes, better convert the image to HSV and try the 'InRangeS' function. Here is an example to track two different colors at same time:

https://github.com/abidrahmank/OpenCV-Python/blob/master/Other_Examples/multi_color_two_object.py

Hope it helps.

Comments

1

Yes - but it's easier in HSV color space. Tutorials here

3 Comments

that is good but i dont think it helps with my problem. il give you a little bit more insight. im trying to determine which player is taking their shot in a snooker match. Each player will have a different piece of colored tape on the snooker cue. the tape will be an unusual color. i am trying to detect this unusual color so i can say if player 1 or 2 is at the table?
Is there anything else that can be used to distinguish which player is taking the shot? Add your comment above to the question.
In fact, there is a code example here using HSV for tracking a yellow coloured object: aishack.in/2010/07/tracking-colored-objects-in-opencv

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.