Python:CV库使用提示cv2.error: OpenCV(x.x.x)或cv2.cv2您需要配置好的 Python 2 SDK 来渲染

        今天在使用CV库时候,图片对话框总是一闪而过,并且报错内容如下:

C:\ProgramData\Anaconda3\python.exe "C:/Users/王/PycharmProjects/test/test0627.py"

[ WARN:[email protected]] global D:\a\opencv-python\opencv-python\opencv\modules\imgcodecs\src\loadsave.cpp (239) cv::findDecoder imread_('C:\Users\王\Desktop\pic\0.png'): can't open/read file: check file path/integrity

Traceback (most recent call last):
  File "C:/Users/王/PycharmProjects/test/test0627.py", line 1000, in 
    console_location(pic_path)
  File "C:/Users/王/PycharmProjects/testtest0627.py", line 956, in console_location
    cv.imshow("img", img)

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'

        刚开始以为是加载时间不足,所以设置了time.sleep(10),但是仍会报错,在网上找了很多的资料,发现只是因为图片路径中包含汉字“王”导致,解决办法如下:

pic_path = 'C:\\Users\\王\\Desktop\\pic\\0.png' 

# CV库使用的文件路径,不能出现中文!!所以下面的代码会报错!!
  img = cv2.imread(path)
# CV库使用包含中文路径的办法!!
  img = cv2.imdecode(np.fromfile(path,dtype=np.uint8),-1)

你可能感兴趣的:(经验总结,程序出错总结,python,python)