赞
踩
- # coding: utf-8
- import numpy as np
- import cv2
-
- img = cv2.imread('1.jpg',1)
- cv2.imshow('image', img)
-
- k = cv2.waitKey(0)
-
- if k == 27:
- cv2.destroyAllWindows()
- elif k == ord('s'):
- cv2.imwrite('保存_1.jpg', img)
- cv2.destroyAllWindows()
按S后图片保存成功,中文乱码如下图:
解决方案:
将cv2.imwrite('保存_1.jpg', img)替换为cv2.imencode('.jpg', img)[1].tofile(filenpath)
完整代码如下:
- # coding: utf-8
- import numpy as np
- import cv2
-
- img = cv2.imread('1.jpg',1)
- cv2.imshow('image', img)
-
- k = cv2.waitKey(0)
-
- if k == 27:
- cv2.destroyAllWindows()
- elif k == ord('s'):
- #cv2.imwrite('保存_1.jpg', img)
- cv2.imencode('.jpg', img)[1].tofile('保存_1.jpg')
- cv2.destroyAllWindows()
效果:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。