欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Python3 Opencv2 拼接两张图像

程序员文章站 2022-07-13 14:11:00
...

1. 纵向拼接

import cv2
import numpy as np
import pandas as pd

img1 = cv2.imread('E:\\tmp\\xray\\1.png')
img2 = cv2.imread('E:\\tmp\\xray\\1_out.png')

img1 = cv2.resize(img1, (640, 480))
img2 = cv2.resize(img2, (640, 480))

# 核心拼接代码
image = np.vstack((img1, img2))

cv2.imshow("test", image)
cv2.waitKey(0)

Python3 Opencv2 拼接两张图像

2. 水平拼接

import cv2
import numpy as np
import pandas as pd

img1 = cv2.imread('E:\\tmp\\xray\\1.png')
img2 = cv2.imread('E:\\tmp\\xray\\1_out.png')

img1 = cv2.resize(img1, (640, 480))
img2 = cv2.resize(img2, (640, 480))

# 核心代码
image = np.concatenate([img1, img2], axis=1)

cv2.imshow("test", image)
cv2.waitKey(0)

Python3 Opencv2 拼接两张图像

相关标签: Python3