user992520
user992520

Reputation:

Color detection opencv

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?

Upvotes: 6

Views: 14775

Answers (3)

Abid Rahman K
Abid Rahman K

Reputation: 52646

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.

Upvotes: 3

Jav_Rock
Jav_Rock

Reputation: 22245

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.

Upvotes: 3

Martin Beckett
Martin Beckett

Reputation: 96167

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

Upvotes: 1

Related Questions