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

Use **img = cv2.imread(imgPath)** to open the picture and report an error:

cv2.error: OpenCV(4.5.1) C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-oduouqig\opencv\modules\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'

Use print(img) to print also as None. At this time, there are two possibilities:
1. The path is wrong, the file corresponding to the path does not exist, check the path
2. If there is Chinese in the path or the file name is in Chinese,
you can change the Chinese name. Or another way of reading:

import cv2
import numpy as np
imgPath="E:/program/python/test/test1/我的.PNG"
img=cv2.imdecode(np.fromfile(imgPath, dtype=np.uint8), -1)

Guess you like

Origin blog.csdn.net/liulanba/article/details/114582347