Friday, September 26, 2025
HomeLanguagesPython OpenCV – haveImageWriter() function

Python OpenCV – haveImageWriter() function

In this article, we are going to learn about the haveImageWriter() function of the OpenCV library.

haveImageWriter() function

Sometimes we need to detect if the specified image file is being correctly written or not before continuing further, In such a case we can use OpenCV which helps us to process images and videos to identify objects. When openCV is integrated with methods like the haveImageWriter() function. It helps us to check whether specified images can be encoded or written successfully or not. below is the syntax of the haveImageWriter function.

Syntax: cv.haveImageWriter(filename)

Parameters:

  • filename: Filename of the image.

Return: True, if specified image written successfully otherwise it returns False.

Example 1: 

We will use the following image extension in our code and check whether it can be read correctly or not. Any image file with extension jpg, png, and jpeg will return True.

Python3




# Import the library OpenCV
import cv2
  
# Use haveImageWriter() function to check
# provided image file can be encoded or not
return_val = cv2.haveImageWriter("gfg.png")
  
# Print the returned value
print(return_val)


Output:

True

Example 2: 

Any image file with an extension with a GIF will return False. 

Python3




# Import the library OpenCV
import cv2
  
# Use haveImageWriter() function to check
# provided image file can be encoded or not
return_val = cv2.haveImageWriter("apple.gif")
  
# Print the returned value
print(return_val)


Output:

False

Example 3: 

Any image file with extensions other than jpg, png, and jpeg will return False.

Python3




# Import the library OpenCV
import cv2
  
# Use haveImageWriter() function to check
# provided image file can be encoded or not
return_val = cv2.haveImageWriter("apple.mp4")
  
# Print the returned value
print(return_val)


Output:

False
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32320 POSTS0 COMMENTS
Milvus
84 POSTS0 COMMENTS
Nango Kala
6683 POSTS0 COMMENTS
Nicole Veronica
11854 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11910 POSTS0 COMMENTS
Shaida Kate Naidoo
6795 POSTS0 COMMENTS
Ted Musemwa
7071 POSTS0 COMMENTS
Thapelo Manthata
6755 POSTS0 COMMENTS
Umr Jansen
6762 POSTS0 COMMENTS