ConvertImage

For purely historical reasons, there is one orphan routine in the HighGUI that fits into none of the categories described above. It is so tremendously useful, however, that you should know about it and what it does. The function is called cvConvertImage().

void cvConvertImage(
  const CvArr* src,
  CvArr*       dst,
  int          flags = 0
);

cvConvertImage() is used to perform common conversions between image formats. The formats are specified in the headers of the src and dst images or arrays (the function prototype allows the more general CvArr type that works with IplImage).

The source image may be one, three, or four channels with either 8-bit or floating-point pixels. The destination must be 8 bits with one or three channels. This function can also convert color to grayscale or one-channel grayscale to three-channel grayscale (color). Finally, the flag (if set) will flip the image vertically. This is useful because sometimes camera formats and display formats are reversed. Setting this flag actually flips the pixels in memory.

Get Learning OpenCV now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.