HomeLanguagesPython OpenCV – haveImageReader() function

Python OpenCV – haveImageReader() function

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    
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32688 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
7057 POSTS0 COMMENTS
Nicole Veronica
12198 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12293 POSTS0 COMMENTS
Shaida Kate Naidoo
7182 POSTS0 COMMENTS
Ted Musemwa
7447 POSTS0 COMMENTS
Thapelo Manthata
7160 POSTS0 COMMENTS
Umr Jansen
7150 POSTS0 COMMENTS