检查图片是否成功加载
if img1 is None or img2 is None:
print(Error loading images)
else:
确保两张图片具有相同的高度
if img1.shape[0] != img2.shape[0]:
print(Images must have the same height to merge horizontally.)
else:
水平合并
merged_image = np.hstack((img1, img2))
检查图片是否成功加载
if img1 is None or img2 is None:
print(Error loading images)
else:
确保两张图片具有相同的宽度
if img1.shape[1] != img2.shape[1]:
print(Images must have the same width to merge vertically.)
else:
垂直合并
merged_image = np.vstack((img1, img2))