opencv python3合并代理奇怪

时间:2018-12-04 12:34:14

标签: python-3.x merge opencv3.0

几个小时以来,我一直在为cv2.merge()的这种奇怪行为寻找答案。

简而言之,我正在合并3张uint8 1通道图像,尺寸为960x1280,得到了960x1280x3的合并图像, 但是每个通道的分辨率都是1280x3,而不是960x1280。

结果,我无法绘制它。

我正在使用以下方法加载每个图像:

        img = cv2.imread(file).astype(np.uint8)
        if len(img.shape) > 2:  img = img[:,:,1]

以下是合并代码(带有其他信息):

alg = (img1,img2,img3)
print('type: ',type(alg[0]),type(alg[1]),type(alg[2]))
print('dtype: ',alg[0].dtype, alg[1].dtype, alg[2].dtype)
print('shape: ',alg[0].shape, alg[1].shape, alg[2].shape)

PseudoRGB = cv2.merge(alg)
print('\nmerged type: ',type(PseudoRGB))
print('merged dtype: ',PseudoRGB.dtype)
print('merged shape: ',PseudoRGB.shape)
print('merged shape, each channel: ',PseudoRGB[0].shape, PseudoRGB[1].shape, PseudoRGB[2].shape)

那给了我

type:  <class 'numpy.ndarray'> <class 'numpy.ndarray'> <class 'numpy.ndarray'>
dtype:  uint8 uint8 uint8
shape:  (960, 1280) (960, 1280) (960, 1280)

merged type:  <class 'numpy.ndarray'>
merged dtype:  uint8
merged shape:  (960, 1280, 3)
merged shape, each channel:  (1280, 3) (1280, 3) (1280, 3)

非常感谢您的帮助。

0 个答案:

没有答案