Convert OpenCV image to grayscale

Standard

ITo load an image or convert an OpenCV image in grayscale, simply use the code below:

OpenCV C++ image grayscale:

OpenCV Python image grayscale:

Altternatively, you can convert a color image to grayscale.

 

Output:

OpenCV Grayscale image cat

 

Loading an image in OpenCV

Standard

OpenCV Images are held in the Mat data structure. The IplImage data structure is deprecated. OpenCV offers support for the image formats Windows bitmap (bmp), portable image formats (pbm, pgm, ppm) and Sun raster (sr, ras). With help of plugins  you may also load image formats like JPEG (jpeg, jpg, jpe), JPEG 2000 (jp2), TIFF files (tiff, tif) and portable network graphics (png).

 OpenCV Load Image C++
To load and display an image using OpenCV:

Compilation:

Output:

OpenCV Window

OpenCV Load Image Python