1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| import numpy as np
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['SimHei']
from PIL import Image import cv2 as cv
def show(img, title='null'): if type(img) == np.ndarray: if img.ndim == 2: plt.imshow(img,cmap='gray') else : plt.imshow(cv.cvtColor(img,cv.COLOR_BGR2RGB)) else: img_ndim = len(np.array(img).shape) if img_ndim == 3: plt.imshow(img) elif img_ndim == 2: plt.imshow(img, cmap='gray') else: print("PIL类型图片的维度异常,维度:",img_ndim) if title != 'null': plt.title(title, fontsize=18) plt.show()
def show_cv(img, title='123'): cv.namedWindow(title,flags=cv.WINDOW_NORMAL) h,w,r = img2.shape cv.resizeWindow(title,w,h) cv.imshow(title,img) cv.waitKey(0) cv.destroyAllWindows() _ = cv.waitKey(1)
|