Color detection in opencv

前端 未结 1 593
慢半拍i
慢半拍i 2020-12-08 12:37

I want to detect a specific color say, blue, from a live video stream. I have written the following code which displays the live video stream and change it into HSV and gray

相关标签:
1条回答
  • 2020-12-08 13:00

    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:

    enter image description here

    0 讨论(0)
提交回复
热议问题