这就是对我有用的...
import cv2
import numpy as np
#Created an image (really an ndarray) with three channels
new_image = np.ndarray((3, num_rows, num_cols), dtype=int)
#Did manipulations for my project where my array values went way over 255
#Eventually returned numbers to between 0 and 255
#Converted the datatype to np.uint8
new_image = new_image.astype(np.uint8)
#Separated the channels in my new image
new_image_red, new_image_green, new_image_blue = new_image
#Stacked the channels
new_rgb = np.dstack([new_image_red, new_image_green, new_image_blue])
#Displayed the image
cv2.imshow("WindowNameHere", new_rgbrgb)
cv2.waitKey(0)
0
我正在尝试将代表黑白图像的2D Numpy数组转换为3通道OpenCV数组(即RGB图像)。
基于代码示例和文档,我正在尝试通过Python进行此操作,例如:
但是,对CvtColor()的调用将引发以下cpp级异常:
我究竟做错了什么?