显示图片及保存
path不能有中文
1 import cv2 2 3 img = cv2.imread(path) 4 cv2.imshow('image',img)#image是 窗口名称 5 cv2.waitkey(0) 6 7 cv2.imwrite(path,img)
若有中文,保存不会报错,但会显示False,并且保存不了
可使用imencoder
1 img = cv2.imread(path) 2 imwrite = cv2.imencoder('.jpg',img)[1].tofile('中文path')
示例
1 import os 2 os.chdir(r'C:\Users\WG\Desktop\新建文件夹 (2)') 3 img = cv2.imread('15.jpg') 4 # cv2.imshow('img',img) 5 # cv2.waitKey(0) 6 #cv2.imwrite(r'C:\Users\WG\Desktop\a\2.jpg',img) 7 cv2.imencode('.png',img)[1].tofile(r'C:\Users\WG\Desktop\新建文件夹 (3)\test.png')
成功!
标签:WG,img,cv2,保存,jpg,Desktop,opencv,path,图片 From: https://www.cnblogs.com/w982148620/p/17553556.html