Get image from Point Grey camera using PyCapture2 and OpenCV

5.5k Views Asked by At

I am trying to get image from Point Grey Camera using PyCapture2, provided by them as a python wrapper for FlyCapture2. I can take retrieve the image buffer but I am not able to get image as Mat datatype to be used in OpenCV.

For reference:

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)

How to convert this rgb_object into a Mat Image?

1

There are 1 best solutions below

1
On

This is what I did:

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)

And if you want color image:

color_cv_image = cv2.cvtColor(cv_image, cv2.COLOR_BAYER_BG2BGR)

reference: http://answers.opencv.org/question/74788/point-grey-usb3-camera-pixel-color-format/