经过测试,发现cv2.imread读取图片,路径中有中文,则返回null
cv2.imread 中文路径返回null
这个方法还没试:
-
file = askopenfilename()
-
im2 = cv2.imread(file.encode('gbk')
opencv c++是支持中文的,python不支持中文。
读取图片
import cv2
img = cv2.imdecode(np.fromfile(img_path, dtype=np.uint8), 1)
img = cv2.imdecode(np.fromfile(img_path, dtype=np.uint8), -1) # 读入完整图片,见下面解释
img = cv2.imdecode(np.fromfile(img_path, dtype=np.uint8), 0) # 读成灰度
img = cv2.imdecode(np.fromfile(img_path, dtype=np.uint8), 1) # 读成彩图