尝试合并两张图片以创建一张图片时:
img3 = imread('image_home.png')
img4 = imread('image_away.png')
result = np.hstack((img3,img4))
imwrite('Home_vs_Away.png', result)
有时会出现以下错误:
all the input array dimensions for the concatenation axis must match exactly, but along dimension 0, the array at index 0 has size 192 and the array at index 1 has size 191
当 np.hstack
无法使用时,如何处理数组大小之间的差异以生成图像?
注意:
我使用多张图片,因此最大的图像不一定总是第一张,也不一定总是第二张,最小和最大的顺序可能会相当随机。
shape
来分析哪个图像最大,并创建IF ELIF
是否是最快和最聪明的方法? - Digital Farmerif (img1.shape[0] > img2.shape[0]): cv2.resize(img2, img1.shape[:2][::-1])
elif (img2.shape[0] > img1.shape[0]): cv2.resize(img1, img2.shape[:2][::-1]):
? - Digital Farmer