Changing Colorspaces — OpenCV 3.0.0 | opencv inrange threshold
GoalInthistutorial,youwilllearnhowtoconvertimagesfromonecolor-spacetoanother,likeBGRGray,BGRHSVetc.Inadditiontothat,wewillcreateanapplicationwhichextractsacoloredobjectinavideoYouwilllearnfollowingfunctions:cv2.cvtColor(),cv2.inRange()etc.ChangingColor-spaceTherearemorethan150color-spaceconversionmethodsavailableinOpenCV.Butwewilllookintoonlytwowhicharemostwidelyusedones,BGRGrayandBGRHSV.Forcolorconversion,weusethefunctioncv2.cvtColor(input_image,flag)whereflagdeterminesthetypeofconversion.F...
Goal In this tutorial, you will learn how to convert images from one color-space to another, like BGR Gray, BGR HSV etc. In addition to that, we will create an application which extracts a colored object in a video You will learn following functions : cv2.cvtColor(), cv2.inRange() 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 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 flagsNot...