我有以下代码:
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通道。如何修改我的代码?
发布于 2018-06-04 18:36:30
我相信你是在找np.dstack
result = np.dstack((img, gray))
https://stackoverflow.com/questions/50678519
复制相似问题