J
J
JRBRO2022-04-21 14:20:20
Python
JRBRO, 2022-04-21 14:20:20

Python skip if such-and-such output, how to write?

Such a question, there is a cv2 script that is in a loop and goes through two folders. The problem occurs if one image is missing from the loop. How to write if such output in console, then move on to the next and else proceed as usual.

cv2.error: OpenCV(4.5.5) D:\a\opencv-python\opencv-python\opencv\modules\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'

Here is such an error in the console, how to teach the script, if it appears, do not crash, but go to the next value from the list.

num = open("num.csv", "r")
for b in num:
...
тут идет все про путь, обработку и т.д
...
cv2.imshow('before'+(b), before)
cv2.waitKey(0)
cv2.destroyAllWindows()


And until the moment of error, he beautifully closes one, opens another.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
J
JRBRO, 2022-04-21
@JRBRO

I solved everything simply - try:
...
except:
pass

A
Andrey Myvrenik, 2016-10-17
@gim0

I had a similar problem with the Intel driver. Judging by the answers in this thread , this happens when the libraries supplied with Android Studio are not compatible with the video driver installed on the system. I solved it by deleting the following files:

rm -rf $ANDROID_HOME/Sdk/tools/lib/libstdc++
rm -rf $ANDROID_HOME/Sdk/tools/lib64/libstdc++

Once uninstalled, AS will use the libstd installed on the system. The $ANDROID_HOME environment variable contains the path to the android SDK and it may not be set in your case, so find where AS stores the android SDK.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question