1

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

buckett
  • 57
  • 1
  • 10
  • not sure I understand your problem... your current program works, but it shows images one at the time and not in a flow? have you tried to put a number like 10 or 30 in the cv2.waitKey() function? that should make your loop update the frame in a flow. Or you mean that it can only retrieve one image and then the program hangs/crashes? – api55 Sep 26 '17 at 10:10

3 Answers3

3

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.

user3053452
  • 640
  • 1
  • 12
  • 38
Eyal S.
  • 1,141
  • 4
  • 17
  • 29
  • Thanks Mate,Do you have anymore information on the Pycapture documentation. I'm Currently having trouble configuring all the camera setting. I am following https://qiita.com/YutaYANAGITYAYA/items/1ab61671d8cc69d7ade7 but my Japanese is in poor form right now – buckett Oct 02 '17 at 10:39
  • 2
    After installation, the pycapture folder includes a bunch of examples and a document describing all of the different classes. – Eyal S. Oct 03 '17 at 19:44
  • 1
    I spoke to Point Grey about this issue and it seems like they fixed it. They sent me a beta release that works well (the full release is still not available). – Eyal S. Oct 04 '17 at 15:16
  • 1
    The image.getData() now returns a numpy array and it is way faster. I was able to stream a video with a fairly high refresh rate. – Eyal S. Oct 04 '17 at 15:17
  • 2
    Which version we're talking about of the SDK lib? – ZF007 Mar 04 '18 at 10:31
1

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.

Bret
  • 11
  • 1
0

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

e.g. cv2.waitKey(10)