Color detection in opencv

半腔热情 提交于 2019-11-28 06:07:22
Haris

You can do this in three steps:

  1. Load frame.
  2. Convert BGR to HSV color space.
  3. Inrange between the color range to detect.

Edit

You can use this code to find the HSV value of any pixel from your source image. You can see a good explanation about HSV color space here, download the HSV colour wheel from there and manually find out the HSV range.

The following range can be used for the image supplied in the comments:

hsv_min--> (106,60,90)
hsv_max-->(124,255,255)

The following code can be used:

Mat src=imread("image.jpg");
Mat HSV;
Mat threshold;

cvtColor(src,HSV,CV_BGR2HSV);
inRange(HSV,Scalar(106,60,90),Scalar(124,255,255),threshold);
imshow("thr",threshold);     

This is the output:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!