Python OpenCV Example | Convert a Color Image to Gray

In this python opencv example, we will introduce how to convert a color image to gray. We will use cv2.cvtColor() function to implement it.

Step 1: load a color image

import cv2
img = cv2.imread("bird.jpg")

We will use cv2.imread() to load an image in python opencv.

Step 2: convert it to gray

It is very easy to do. Here is an example:

grey_image = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
cv2.imshow("Gray Image of Bird",grey_image)
cv2.waitKey(0)

Run this code, we may see:

Python OpenCV Example | Convert a Color Image to Gray