I used OpenCV's subtitler to stitch together images, but the effect was not what I wanted [1]: https://i.stack.imgur.com/DXl0a.png [2]: https://i.stack.imgur.com/jGPYB.png [3]: https://i.stack.imgur.com/vAqwE.jpg This question requires a friend who can understand Chinese to answer
import cv2
import numpy as np
# 读取两张图像
image1 = cv2.imread('.\\key\\key11.png')
image2 = cv2.imread('.\\key\\key12.png')
# 获取图像高度和宽度
height1, width1 = image1.shape[:2]
height2, width2 = image2.shape[:2]
# 获取最宽宽度
max_width = max(width1, width2)
# 计算放大倍率
scaling_factor1 = max_width / width1
scaling_factor2 = max_width / width2
# 调整图像大小并进行比例放大
image1_resized = cv2.resize(image1, (max_width, int(height1 * scaling_factor1)))
image2_resized = cv2.resize(image2, (max_width, int(height2 * scaling_factor2)))
# 创建一条分界线
isLine = False
line_color = (0, 0, 255) # 线的颜色(BGR)
line_thickness = 2 # 线的厚度
line = np.ones((5, max_width, 3), dtype=np.uint8) * line_color
# 垂直拼接图像和分界线
if isLine:
combined_image = np.vstack((image1_resized, line, image2_resized))
else:
combined_image = np.vstack((image1_resized, image2_resized))
# 保存拼接后的图像
cv2.imwrite("combined_image.png", combined_image)
print("图像拼接完成。")