Changing Colorspaces | python opencv rgb to hsv
GoalInthistutorial,youwilllearnhowtoconvertimagesfromonecolor-spacetoanother,likeBGR(leftrightarrow)Gray,BGR(leftrightarrow)HSV,etc.Inadditiontothat,wewillcreateanapplicationtoextractacoloredobjectinavideoYouwilllearnthefollowingfunctions:cv.cvtColor()[1],cv.inRange()[2],etc.ChangingColor-spaceTherearemorethan150color-spaceconversionmethodsavailableinOpenCV.Butwewilllookintoonlytwo,whicharemostwidelyusedones:BGR(leftrightarrow)GrayandBGR(leftrightarrow)HSV.Forcolorconversion,weusethefunction...
Goal In this tutorial, you will learn how to convert images from one color-space to another, like BGR (leftrightarrow) Gray, BGR (leftrightarrow) HSV, etc. In addition to that, we will create an application to extract a colored object in a video You will learn the following functions: cv.cvtColor()[1], cv.inRange()[2], etc. 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 (leftrightarrow) Gray and BGR (leftrightarrow) HSV.
For color conversion, we use the function cv.cvtColor(input_image, flag) where flag determines the type of conversion.
For BGR ( ightarrow) Gray conversion, we use the flag cv.COLOR_BGR2GRAY[3]. Similarly for BGR ( ightarrow) HSV, we use the flag cv.COLOR_BGR2HSV[4]. To get other flags, just run following commands in your Python terminal:
>>> import cv2 as cv
>>> flags = [i for i in di...