优化涂抹测试的图片显示

This commit is contained in:
2024-07-26 10:27:11 +08:00
parent d5661524bc
commit 9635a4b206
3 changed files with 34 additions and 12 deletions

View File

@@ -203,3 +203,31 @@ def expand_to_a4_size(image, center=False):
exp_img.fill(255)
image = numpy.vstack([image, exp_img])
return image, offset_x, offset_y
def combined(img1, img2):
# 获取两张图片的高度和宽度
height1, width1 = img1.shape[:2]
height2, width2 = img2.shape[:2]
# 确保两张图片的高度相同
if height1 != height2:
# 如果高度不同,调整较小高度的图片
if height1 < height2:
img1 = cv2.resize(img1, (int(width1 * height2 / height1), height2))
else:
img2 = cv2.resize(img2, (int(width2 * height1 / height2), height1))
# 再次获取调整后的图片尺寸
height1, width1 = img1.shape[:2]
height2, width2 = img2.shape[:2]
# 创建一个空白的图像,宽度等于两张图片的宽度之和,高度等于它们共同的高度
total_width = width1 + width2
max_height = max(height1, height2)
combined_img = numpy.zeros((max_height, total_width, 3), dtype=numpy.uint8)
# 将img1和img2复制到新的图像中
combined_img[:height1, :width1] = img1
combined_img[:height2, width1:width1 + width2] = img2
return combined_img