Open In App

Python OpenCV – haveImageReader() function

Last Updated : 03 Jan, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

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

The haveImageReader() function is used to check whether specified images can be decoded or read successfully by OpenCV or not. Sometimes we need to detect if the specified image file is being correctly read before continuing. In such a case we can use this function.

Syntax: return_value=cv2.haveImageReader(Image_File_Name)

Parameter: 

  • Image_File_Name: Name of the image 

Return value: This method returns True if specified image read successfully otherwise it returns False.

Example 1:

We will use the following image in our code and check whether it can be read correctly or not.

Sky.jpg

Code:

Python3




# Import OpenCV library
import cv2
  
# Use haveImageReader() function to check
# provided image file correctly read or not
return_val = cv2.haveImageReader("Sky.jpg")
  
# print the returned value
print(return_val)


Output:

True 

Example 2:

Now we will check what will be the output when we give the wrong image name.

Python3




# Import OpenCV library
import cv2
  
# Use haveImageReader() function to check
# provided image file correctly read or not
return_val = cv2.haveImageReader("rose.jpg")
  
# print the returned value
print(return_val)


Output:

False    

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads