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.
<take a look at this page you will find HSV values of the color you want.
For HSV, Hue range is [0,179], Saturation range is [0,255] and Value range is [0,255]. Different softwares use different scales. So if you are comparing OpenCV values with them, you need to normalize these ranges.
i guess you are searching the values like below for yellow
lower_blue = np.array([25,50,50])
upper_blue = np.array([32,255,255])
if i want to do it ,first find rgb numbers for yellow (i use 'Edit colors 'in paint) then change them to HSV whith this method:
u = np.uint8([[[0,236,236]]])
# define range of blue color in HSV
lower_yellow = np.array(cv2.cvtColor(l,cv2.COLOR_BGR2HSV))
upper_yellow = np.array( cv2.cvtColor(u,cv2.COLOR_BGR2HSV))```
If you take pictures from a camera, it will depend on lighting condition. If your aim is to track some objects, you should always update your HSV values. My advise is keep your boundary as narrow as possible in your lighting condition.
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