gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) cv2.error: OpenCV(4.1.1) C:\projects\opencv-python\open

在处理图像转灰度的时候遇到如下报错:

Traceback (most recent call last):
  File "C:/Users/yhstc/PycharmProjects/untitled/标定/chass.py", line 34, in <module>
    gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
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'

经过分析是因为路径的问题,opencv在识别到中文路径时会出错,因此将路径名从

images = glob.glob('C:/Users/yhstc/PycharmProjects/untitled/标定/chass/chass*.jpg')

改为

images = glob.glob('C:/Users/yhstc/PycharmProjects/untitled/biaoding/chass/chass*.jpg')

即可

你可能感兴趣的:(日常问题,opencv路径问题)