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.
<
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