Python OpenCV – haveImageWriter() function
Last Updated :
03 Jan, 2023
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 cv2
return_val = cv2.haveImageWriter( "gfg.png" )
print (return_val)
|
Output:
True
Example 2:
Any image file with an extension with a GIF will return False.
Python3
import cv2
return_val = cv2.haveImageWriter( "apple.gif" )
print (return_val)
|
Output:
False
Example 3:
Any image file with extensions other than jpg, png, and jpeg will return False.
Python3
import cv2
return_val = cv2.haveImageWriter( "apple.mp4" )
print (return_val)
|
Output:
False
Share your thoughts in the comments
Please Login to comment...