Identifying the range of a color in HSV using openCV

前端 未结 4 1832
陌清茗
陌清茗 2021-02-03 13:59

I am working on identifying the color yellow using openCV in python. I have come to this step where I have to define the lower and upper range of the color yellow in HSV.

<
4条回答
  •  -上瘾入骨i
    2021-02-03 14:54

    It's Simple. You can use the function, cv2.cvtColor().

    Instead of passing an image, you just pass the BGR values which you want to convert to hsv.

    For Example, to find the HSV value of Green, type the following command

    import numpy as np
    import cv2
    
    green = np.uint8([[[0, 255, 0]]]) #here insert the bgr values which you want to convert to hsv
    hsvGreen = cv2.cvtColor(green, cv2.COLOR_BGR2HSV)
    print(hsvGreen)
    
    lowerLimit = hsvGreen[0][0][0] - 10, 100, 100
    upperLimit = hsvGreen[0][0][0] + 10, 255, 255
    
    print(upperLimit)
    print(lowerLimit)
    

    Now, the Upper Limit will be [H+10, 100,100]

    and Lower Limit will be [H-10, 255, 255]

    Official documentation (see the last part of following webpage) https://docs.opencv.org/3.1.0/df/d9d/tutorial_py_colorspaces.html

提交回复
热议问题