都知道Python2.7版本中文显示问题,在Python3以后就没有这个问题了,但不知道为什么Python3下opencv在打开带有中文名的图片时就有问题。
测试环境:Python3.5、opencv
错误例子:
file = 'C:/测试.jpg'
import cv2
img = cv2.imread(file)
cv2.imshow('test',img)
OpenCV Error: Assertion failed (size.width>0 && size.height>0) in cv::imshow, file C:\projects\opencv-python\opencv\modules\highgui\src\window.cpp, line 325
Traceback (most recent call last):
File "", line 1, in
cv2.error: C:\projects\opencv-python\opencv\modules\highgui\src\window.cpp:325: error: (-215) size.width>0 && size.height>0 in function cv::imshow
img
print(img)
None
file = 'C:/测试.jpg'
import cv2
import numpy as np
img = cv2.imdecode(np.fromfile(file, dtype=np.uint8), -1)
cv2.imencode('.jpg',img)[1].tofile('C:/测试1.jpg')#保存