Stitching two images of different sizes together in Python

foreword

Stitching two images of different sizes together using opencv and numpy.


code show as below:

import cv2
import numpy as np


# 读图
img1 = cv2.imread('luffy.png')
img2 = cv2.imread('lena.tif')

# 第一幅图resize成第二幅图大小
img1_resize = cv2.resize(img1, img2.shape[0:2][::-1])

# 使用numpy.将两幅图拼接在一起
joint = np.hstack((np.array(img1_resize), np.array(img2)))

# 显示
cv2.imshow('img1', img1)
cv2.imshow('img2', img2)
cv2.imshow('joint', joint)
cv2.waitKey(0)

Before splicing:
insert image description here
After splicing:
insert image description here

Guess you like

Origin blog.csdn.net/weixin_45887062/article/details/125654268