[PYTHON] Addresses an issue where an error does not occur even if the path does not pass when trying to read an image with cv2.imread ()

problem

The problem is as the title says.

This is an error that appears when performing image processing using OpenCV on Python. For the Open CV library, it doesn't cause an error even if it doesn't pass, so at first glance it looks like there is no problem with the program. However, there is a problem that the image is not actually loaded.

approach

cv2.py


import cv2

img = cv2.imread('xxxxx')

if img:
    print('Image is read.')
else:
    print('Image is not read.')

Image is not read.

When it is read as above, it is possible to check whether it is read by returning a sentence indicating that it has been read.

Recommended Posts

Addresses an issue where an error does not occur even if the path does not pass when trying to read an image with cv2.imread ()
What to do if pyenv install does not proceed with an error
Workaround if you get an error when trying to install PySide with pip
When reading an image with SimpleITK, there is a problem if there is Japanese in the path
Addresses an issue where Fabric cannot pass unicode to fabric.api.abort
What to do if you get an Undefined error when trying to use pip with pyenv
What to do if the user name is changed and the pyenv library path does not pass
I get an error when trying to install maec 4.0.1.0 with pip
What to do if an error occurs when importing numpy with VScode
What to do if you get an error when trying to load mnist
[AWS] How to deal with WordPress "An error occurred when cropping an image."
An error occurs when trying to import scikit-learn after connecting to Oracle with SQLAlchemy
What to do if you get an error when installing python with pyenv
What to do if you get the error "Error: opencv3: Does not support building both Python 2 and 3 wrappers" when installing openCV 3
Investigate the cause when an error is thrown when python3.8 is not found when using lambda-uploader with python3.8
What to do if you get an Import Error when importing matplotlib with Jupyter
[Python] If you create a file with the same name as the module to be imported, an Attribute Error will occur.
Check when the version does not switch with pyenv
How to create a new file when the specified file does not exist — write if the file exists
If the character you are trying to read does not match the conversion specification, the C> scanf ()> scanf function will leave the character unread in the stream.