In this program, we will write an image or save an image to a file using OpenCV.
Step 1: Import cv2 Step 2: Read the image using opencv.imread() Step 3: Save the image using opencv.imwrite(filename, image)
import cv2 import os image = cv2.imread('testimage.jpg') directory = r'C:\Users\prasa\Desktop' os.chdir(directory) cv2.imwrite('CAMERAMAN.jpg', image)
This program will save the image in the directory as same as the original image directory
Ensure that you have set the proper directory in order for the program to execute without errors.