You can save an image in OpenCV Python by following the given steps. I highly recommend you get the “Computer Vision: Models, Learning, and Inference Book” to learn Computer Vision.
Open the Spyder IDE (integrated development environment).
Import the OpenCV library. If OpenCV is not installed in your system then first install it using This Method.
import cv2 #cv2 is used for OpenCV library
Now read the image from the location. In my case “F:\\AiHints” is the location and “top30.png” is the name of the image. Change it according to your image location and name.
image = cv2.imread("F:\\AiHints\\top30.png") #imread is used to read an image from a location
For Example, I want to resize the above image then I will save the resized image with a new name in the next step.
image = cv2.resize(image,(600,300)) #width, height
Now write this code to save the image. In this code “F:\\AiHints” is the location where I will save this image and “Resized.png” will be the name of the image. Change it according to your desired image location and image name.
image = cv2.imwrite('F:\\AiHints\\Resized.png',image) #imwrite is used to save an image at given location with a given name