Hello Guys,

In this article, I will discuss about how to write images in OpenCV.

For writing images, Opencv has the function named “imwrite“. This function takes two arguments.

 1. Image name with extension
 2. Image object

This function returns a boolean. If it writes the file successfully then it returns True, otherwise False.

# Import cv2 module
import cv2 as cv

#reading an using imread function without passing any parameter
# By default it loads the image in color format
colored_image= cv.imread("nature.jpg") 

#imwrite returns True if it writes the file successfully otherwise #returns False

result = cv.imwrite("nature.png",colored_image)

if result:
    png_img = cv.imread("nature.png")
    cv.imshow("Png Image",png_img)
    cv.waitKey(0)
    cv.destroyAllWindows()
else:
    print("Error in writing file")

Also don’t forget to check my previous OpenCV tutorials. 

http://techievaibhav.in/category/programming/opencv/

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments