PyCapture2 Video through opencv

5.1k Views Asked by At

Having trouble importing my Point Grey Chameleon3 camera through opencv and PyCapture2. Currently Taking photos/images individually but want a constant flow.I think it has to do with camera.retrieveBuffer() but can not find a way around.

import PyCapture2
import cv2
import matplotlib.pyplot as plt
import numpy as np
from PIL import Image

bus = PyCapture2.BusManager()
numCams = bus.getNumOfCameras()
camera = PyCapture2.Camera()
uid = bus.getCameraFromIndex(0)
camera.connect(uid)
camera.startCapture()

while True:
    image = camera.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)
    cv2.waitKey(10)

If anyone has any pointers or links to more documentation would be greatly appreciated Thanks

3

There are 3 best solutions below

5
On BEST ANSWER

I'm using a very similar code with a BlackFly camera. The flow problem is because the loop is very slow. You are calling image.getData() twice which makes the problem somewhat worse but the main issue is that reading and converting the data into an image format is very slow.

Diving a little deeper and timing some functions on my computer (my image is 1920 by 1200):

image = camera.retrieveBuffer() - takes about as much time as the set frame rate.

image.getData() takes about 220 ms.

np.array(image.getData(), dtype="uint8").reshape((image.getRows(), image.getCols()) ) takes about 540 ms.

So the refresh rate cannot be faster than that.

0
On

Change the "cvs.waitkey()" time and it should work:

e.g. cv2.waitKey(10)

0
On

I found the PyCapture2 library here. I downloaded the library, then I navigated to my python install then into the docs.

PYTHON_PATH/PyCapture2/docs

The path can also be found by:

import PyCapture2
PyCapture2.__path__

Anyways, If you are looking for the docs or the module itself, you can find them there.