如何显示不同分辨率的垂直 2 图像?
How do I display vertical 2 images with different resolution?
我试过这个:
import cv2
import numpy as np
import matplotlib.pyplot as plt
top=cv2.imread('top.jpg')
bottom=cv2.imread('bottom.jpg')
numpy_vertical= np.vstack((top, bottom))
cv2.imshow('detected', numpy_vertical)
cv2.imwrite('detected.jpg', numpy_vertical)
ValueError: 串联轴的所有输入数组维度必须完全匹配,但沿着维度 1,索引 0 处的数组大小为 2878,索引 1 处的数组大小为尺码 5760
我以下面的图片为例:
第一张图片:
第二张图片:
输出图像
使用以下代码:
import cv2
import numpy as np
first = cv2.imread(r"path.... \first.png")
second = cv2.imread(r"path.... \second.png")
h1, w1, c1 = first.shape
h2, w2, c2 = second.shape
h, w= h1+h2, max(w1, w2)
out_image = np.zeros((h,w,c1))
out_image[:h1,:w1, ] = first
out_image[h1:h1+h2,:w2, ] = second
cv2.imwrite(r"path ......out.png", out_image)
也可以使用 matplotlib 中的子图,如果你只是想可视化图像
import matplotlib.pyplot as plt
first = cv2.imread(r"path.... \first.png")
second = cv2.imread(r"path.... \second.png")
plt.figure()
plt.subplot(121)
plt.imshow(first)
plt.subplot(122)
plt.imshow(second)
plt.show()
我试过这个:
import cv2
import numpy as np
import matplotlib.pyplot as plt
top=cv2.imread('top.jpg')
bottom=cv2.imread('bottom.jpg')
numpy_vertical= np.vstack((top, bottom))
cv2.imshow('detected', numpy_vertical)
cv2.imwrite('detected.jpg', numpy_vertical)
ValueError: 串联轴的所有输入数组维度必须完全匹配,但沿着维度 1,索引 0 处的数组大小为 2878,索引 1 处的数组大小为尺码 5760
我以下面的图片为例:
第一张图片:
第二张图片:
输出图像
使用以下代码:
import cv2
import numpy as np
first = cv2.imread(r"path.... \first.png")
second = cv2.imread(r"path.... \second.png")
h1, w1, c1 = first.shape
h2, w2, c2 = second.shape
h, w= h1+h2, max(w1, w2)
out_image = np.zeros((h,w,c1))
out_image[:h1,:w1, ] = first
out_image[h1:h1+h2,:w2, ] = second
cv2.imwrite(r"path ......out.png", out_image)
也可以使用 matplotlib 中的子图,如果你只是想可视化图像
import matplotlib.pyplot as plt
first = cv2.imread(r"path.... \first.png")
second = cv2.imread(r"path.... \second.png")
plt.figure()
plt.subplot(121)
plt.imshow(first)
plt.subplot(122)
plt.imshow(second)
plt.show()