Choosing the correct upper and lower HSV boundaries for color detection with`cv::inRange` (OpenCV)

前端 未结 6 1970
旧巷少年郎
旧巷少年郎 2020-11-22 11:57

I have an image of a coffee can with an orange lid position of which I want to find. Here is it \"image\".

gcol

6条回答
  •  被撕碎了的回忆
    2020-11-22 12:43

    Ok, find color in HSV space is an old but common question. I made a hsv-colormap to fast look up special color. Here it is:

    The x-axis represents Hue in [0,180), the y-axis1 represents Saturation in [0,255], the y-axis2 represents S = 255, while keep V = 255.

    To find a color, usually just look up for the range of H and S, and set v in range(20, 255).

    To find the orange color, we look up for the map, and find the best range: H :[10, 25], S: [100, 255], and V: [20, 255]. So the mask is cv2.inRange(hsv,(10, 100, 20), (25, 255, 255) )

    Then we use the found range to look for the orange color, this is the result:


    The method is simple but common to use:

    #!/usr/bin/python3
    # 2018.01.21 20:46:41 CST
    import cv2
    
    img = cv2.imread("test.jpg")
    hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
    mask = cv2.inRange(hsv,(10, 100, 20), (25, 255, 255) )
    cv2.imshow("orange", mask);cv2.waitKey();cv2.destroyAllWindows()
    

    Similar answers:

    1. How to define a threshold value to detect only green colour objects in an image :Opencv

    2. Choosing correct HSV values for OpenCV thresholding with InRangeS

提交回复
热议问题