指定宽或高按比例缩放图片
import cv2
def resize_by_ratio(image, width=None, height=None, inter=cv2.INTER_AREA):img_new_size = None(h, w) = image.shape[:2] if width is None and height is None: return image if width is None: h_ratio = height / float(h) img_new_size = (int(w * h_ratio), height) else:w_ratio = width / float(w)img_new_size = (width, int(h * w_ratio))resized = cv2.resize(image, img_new_size, interpolation=inter)return resized
def cv_show(img):cv2.imshow('name',img)cv2.waitKey(0) cv2.destroyAllWindows()
img = cv2.imread('img1.jpeg')
img = resize_by_ratio(img,width=300)
cv2.imwrite('img2_new.jpg',img)
拼接图片
img1 = cv2.imread('start.png')
img2 = cv2.imread('record.png')
img3 = cv2.imread('end.png')
img = np.hstack((img1,img2,img3))
cv_show(img)