OpenCV  3.4.15
Open Source Computer Vision
Changing Colorspaces

Goal

cvtColor

There are more than 150 color-space conversion methods available in OpenCV. But we will look into the most widely used one: RGB \(\leftrightarrow\) Gray.

We use the function: cv.cvtColor (src, dst, code, dstCn = 0)

Parameters
srcinput image.
dstoutput image of the same size and depth as src
codecolor space conversion code(see cv.ColorConversionCodes).
dstCnnumber of channels in the destination image; if the parameter is 0, the number of the channels is derived automatically from src and code.

For RGB \(\rightarrow\) Gray conversion we use the code cv.COLOR_RGBA2GRAY.

Try it

inRange

Checks if array elements lie between the elements of two other arrays.

We use the function: cv.inRange (src, lowerb, upperb, dst)

Parameters
srcfirst input image.
lowerbinclusive lower boundary Mat of the same size as src.
upperbinclusive upper boundary Mat of the same size as src.
dstoutput image of the same size as src and cv.CV_8U type.

Try it