我正在尝试使用PyCapture2从Point Grey Camera获取图像,它们是由FlyCapture2提供的python包装器。我可以检索图像缓冲区,但我无法将图像作为Mat数据类型在OpenCV中使用。
供参考:
while not cv2.waitKey(100) & 0xFF == ord('q'):
try:
raw_object = camera.retrieveBuffer()
except PyCapture2.Fc2error as fc2Err:
print "Error retrieving buffer : ", fc2Err
continue
rgb_object = raw_object.convert(PyCapture2.PIXEL_FORMAT.BGR)
如何将此rgb_object转换为Mat Image?
答案 0 :(得分:2)
这就是我所做的:
image = cam.retrieveBuffer()
row_bytes = float(len(image.getData()))/float(image.getRows());
cv_image = np.array(image.getData(), dtype="uint8").reshape( (image.getRows(), image.getCols()) );
cv2.imshow('frame',cv_image)
如果你想要彩色图像:
color_cv_image = cv2.cvtColor(cv_image, cv2.COLOR_BAYER_BG2BGR)
参考:http://answers.opencv.org/question/74788/point-grey-usb3-camera-pixel-color-format/