Friday, July 24, 2026
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
32520 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6902 POSTS0 COMMENTS
Nicole Veronica
12017 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12115 POSTS0 COMMENTS
Shaida Kate Naidoo
7023 POSTS0 COMMENTS
Ted Musemwa
7265 POSTS0 COMMENTS
Thapelo Manthata
6980 POSTS0 COMMENTS
Umr Jansen
6971 POSTS0 COMMENTS