Changing Colorspaces — OpenCV | hsv blue range
ChangingColor-spaceTherearemorethan150color-spaceconversionmethodsavailableinOpenCV.Butwewilllookintoonlytwowhicharemostwidelyusedones,BGRGrayandBGRHSV.Forcolorconversion,weusethefunctioncv2.cvtColor(input_image,flag)whereflagdeterminesthetypeofconversion.ForBGRGrayconversionweusetheflagscv2.COLOR_BGR2GRAY.SimilarlyforBGRHSV,weusetheflagcv2.COLOR_BGR2HSV.Togetotherflags,justrunfollowingcommandsinyourPythonterminal:>>>importcv2>>>flags=[iforiindir(cv2)ifi.startswith(COLOR_)]...
Changing Color-spaceThere are more than 150 color-space conversion methods available in OpenCV. But we will look into only two which are most widely used ones, BGR Gray and BGR HSV.
For color conversion, we use the function cv2.cvtColor(input_image, flag) where flag determines the type of conversion.
For BGR Gray conversion we use the flags cv2.COLOR_BGR2GRAY. Similarly for BGR HSV, we use the flag cv2.COLOR_BGR2HSV. To get other flags, just run following commands in your Python terminal :
>>> import cv2 >>> flags = [i for i in dir(cv2) if i.startswith(COLOR_)] >>> print flagsNote
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.
Object TrackingNow we know how to convert BGR image to HSV, we can use this ...