Color space and type conversion

Converting various color spaces and types to each other is extremely important, especially when it comes to dealing with images from different device types or intending to display them on different devices and formats. Let's see what this means with a very simple example. You'll need grayscale images for various OpenCV functions and computer vision algorithms, while some will require RGB color images. In such cases, you can use the cvtColor function to convert between various color spaces and formats.

The following is an example that converts a color image to grayscale:

ColorConversionCodes code = COLOR_RGB2GRAY; 
cvtColor(image, 
         result, 
         code); 

code can take a conversion code, which must be an entry from the ColorConversionCodes enum. The following are some examples of the most popular color-conversion codes, that can be used with the cvtColor function:

  • COLOR_BGR2RGB
  • COLOR_RGB2GRAY
  • COLOR_BGR2HSV

The list goes on and on. Make sure to check the ColorConversionCodes enum for all possible color-conversion codes.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.220.187.223