Identifying the range of a color in HSV using openCV | hsv blue range
ItsSimple.Youcanusethefunction,cv2.cvtColor().Insteadofpassinganimage,youjustpasstheBGRvalueswhichyouwanttoconverttohsv.ForExample,tofindtheHSVvalueofGreen,typethefollowingcommandimportnumpyasnpimportcv2green=np.uint8([[[0,255,0]]])#hereinsertthebgrvalueswhichyouwanttoconverttohsvhsvGreen=cv2.cvtColor(green,cv2.COLOR_BGR2HSV)print(hsvGreen)lowerLimit=hsvGreen[0][0][0]-10,100,100upperLimit=hsvGreen[0][0][0]+10,255,255print(upperLimit)print(lowerLimit)Now,theUpperLimitwillbe[H+10,100,100]andLo...
Its 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[1]
References https://docs.opencv.org/3.1.0/df/d9d/tutorial_py_colorspaces.html (docs.opencv.org)