У меня есть следующий код:
import cv2
import numpy as np
img = cv2.imread('a.jpg')
gray = cv2.imread('b.jpg')
gray = cv2.cvtColor(gray, cv2.COLOR_BGR2GRAY)
print('a shape:', img.shape) # a shape: (50,50,3)
print('b shape:', img.shape) # b shape: (50,50)
result = np.concatenate((img, gray), axis=2)
print('result: ', result.shape) # hope result shape: (50, 50, 4)
Я получаю следующее исключение:
ValueError: all the input arrays must have same number of dimensions
Я хочу получить result.shape = (50, 50, 4), 4 канала. Как изменить мой код?






Я считаю, что вы ищете np.dstack:
result = np.dstack((img, gray))