python opencv合并图片
# -*- coding = utf-8 -*-
# @Time : 2021/2/9 19:20
# @Author : 水神与月神
# @File : 图片合并(2021.2.9).py
# @Software : PyCharm
import cv2 as cv
import numpy as np
# 图片读取路径
path1 = r''
path2 = r''
# 图片保存路径
path3 = r''
# 读取图片,保持图片原格式不变
img1 = cv.imread(path1, cv.IMREAD_UNCHANGED)
img2 = cv.imread(path2, cv.IMREAD_UNCHANGED)
# 连接图片
image = np.concatenate((img1, img2), axis=0)
# 显示图片
cv.namedWindow('image', 0)
cv.imshow('image', image)
cv.waitKey(0)
cv.destroyWindow('image')
# 保存图片
cv.imwrite(path3,image)
将路径改成自己图片的路径,运行程序后显示合并之后的图片,键盘按下任意键后,窗口消失、图片保存。