亲宝软件园·资讯

展开

opencv影像拼接

kuokay 人气:0

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)

加载全部内容

相关教程
猜你喜欢
用户评论