Save an Image in Python OpenCV

In this tutorial, we will use an example to show opencv beginners how to save an image. We will use cv2.imwrite() function.

1. Import library

import cv2

2. Read an image and convert it to gray

image = cv2.imread('C:/Users/N/Desktop/Test.jpg')
image_gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

3. Save new gray image

cv2.imwrite('C:/Users/N/Desktop/Test_gray.jpg', image_gray)