error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor' error analysis

1. Terminal output error example:

 File "F:/dmarks.py", line 143, in detect
    orgimg = cv2.cvtColor(im, cv2.COLOR_BGR2RGB)
cv2.error: OpenCV(4.6.0) D:\a\opencv-python\opencv-python\opencv\modules\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'

2. Error message on the code side:

My read path:

 hint:

 Error analysis:

1. According to the error reminder output by the terminal

 error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'

It can be seen that this error is an error that occurs when the image is read or input;

2. According to the error reminder on the code side, it can be known that the length of the read path set for one reason (I am 142 here) has exceeded the recognizable path length (the maximum reminder here is 120), so the length of the path must be changed first , then run the code again; see if the problem is resolved.

3. If it is still not resolved, it is recommended to check whether the folder to be read contains files in other formats, for example: I want to read pictures in jpg format, but when using labelme to label, the json file will also automatically generated in the same file. (Just delete files in other formats)

Guess you like

Origin blog.csdn.net/qq_58611650/article/details/127320693