解决cv2.error: OpenCV(4.1.1) C:\projects\opencv-python\opencv\modules\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'

I reported an error when running, as shown below

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

 

 Then go online to find a solution, summarize some problems that will arise

1. The picture path is written in the following form: E: \ The
correct one should be: E: /
(the slash ' \' has the meaning of escape character in the program )

In short, a slash in front of the picture is /

 2. There is a slash less in the picture path (the picture is stored in the test folder)

Error: C: / Users / Desktop / test is
correct: C: / Users / Desktop / test /
(Do not forget the last slash, otherwise the read will become the test folder instead of the Picture)

 3. The format of the picture is wrong!

 4. The number of pictures is inconsistent!

 5. Do not include Chinese in the path or folder name! This is also very important

6. Be sure to use the absolute path, and clearly locate the position of your picture (this is a problem that you may ignore)

Refer to the following blog post:

https://blog.csdn.net/weixin_43358444/article/details/83217902

Guess you like

Origin www.cnblogs.com/qq991025/p/12683113.html