OPENCV FOR PYTHON 学习笔记 - 图像读取显示
# -*- coding: utf-8 -*- import cv2 as cv import numpy as np from matplotlib import pyplot as plt #判断字符串是否是中文 def check_contain_chinese(check_str): for ch in check_str: if '\u4e00' <= ch <= '\u9fff': return True return False img_path = "宸宸.jpg"; if check_contain_chinese(img_path): img = cv.imdecode(np.fromfile(img_path,dtype=np.uint8),cv.IMREAD_COLOR) else: img = cv.imread(img_path,cv.IMREAD_COLOR) #显示图像 cv.namedWindow("img",cv.WINDOW_NORMAL) cv.imshow("img",img) #使用Matplotlib绘图库显示图像 plt.imshow(img,cmap = plt.cm.gray_r) plt.xticks([]),plt.yticks([]) plt.show() key = cv.waitKey(0)&0xFF if key == ord('q'): cv.destroyAllWindows() elif key == ord('s'): #保存图像 cv.imwrite("new.jpg",img) cv.destroyAllWindows()
本文来自博客园,作者:HappyChen2016,转载请注明原文链接:https://www.cnblogs.com/happychen2016/p/15155786.html