本篇文章小编给大家分享一下python opencv实现影像拼接代码示例,文章代码介绍的很详细,小编觉得挺不错的,现在分享给大家供大家参考,有需要的小伙伴们可以来看看。
1.垂直影像拼接 vconcat
# -*- coding: utf-8 -*- import cv2 image = cv2.imread("lena.jpg") image_v = cv2.vconcat([image, image]) cv2.imshow("Result", image_v) cv2.waitKey(0)
样式:
2.水平影像拼接 hconcat
# -*- coding: utf-8 -*- import cv2 image = cv2.imread("lena.jpg") image_h = cv2.hconcat([image, image]) cv2.imshow("Result", image_h) cv2.waitKey(0)
样式:
3.纵向拼接多个不同图片
import cv2 img = cv2.imread('icon/big.jpg') img2=cv2.imread("icon/small.jpg") def vconcat_resize_min(im_list, interpolation=cv2.INTER_CUBIC): w_min = min(im.shape[1] for im in im_list) im_list_resize = [cv2.resize(im, (w_min, int(im.shape[0] * w_min / im.shape[1])), interpolation=interpolation) for im in im_list] return cv2.vconcat(im_list_resize) im_v_resize = vconcat_resize_min([img, img2]) cv2.imwrite('opencv_vconcat_resize.jpg', im_v_resize)