mabl / PyPylon

An experimental python wrapper around the Basler Pylon 5 library
BSD 3-Clause "New" or "Revised" License
53 stars 34 forks source link

cam.grab_image() is slow #14

Closed ZacDiggum closed 8 years ago

ZacDiggum commented 8 years ago

Hi, I just started using my Ace 3800-14um with Python via PyPylon. I'm developing a 'real time'-ish PyQt app with a separate frame grabbing thread (basically it's just a loop). That worked fine with my old OpenCV based camera. Now I substituted all the OpenCV stuff with the corresponding PyPylon statements and it's working in principle. But frame grabbing is incredibly slow. I set exposure time to the allowed minimum of 35e-6s, bandwith limit to off and the framerate to 15. Pixel depth is Mono8 and I even decreased the resolution. I expected something around 14fps (the camera's max deliverable fps at full res) minus the time for copying to host. But I get 3 (!) fps...In PylonViewer I have 14fps at full res as should be. When I set the exposure time to 100ms I get 2fps. Images look plausible for the mentioned exposures. Any suggestions? Some cam property to set explicitly? Is grab_frame() in a loop the wrong approach? Could you share some code that works for you when displaying live images?

ZacDiggum commented 8 years ago

I'm reading throught the manual (RTFM :-) ) and hope to find all the relevant parameters. I'd still be grateful for a code example. Just for clarification: changing parameters is effective after stopping and starting over frame acquisition, right? Are there functions in PyPylon that stop and start acquisition besides cam.open() and cam.close()?

mabl commented 8 years ago

Hi @ZacDiggum,

you are on the right track. Actually grab_image() starts and stops a picture stream, and is hence rather slow. It will be a lot faster to do a cam.grap_images(big number) and iteraterate over it.

I'm still not 100% happy with the frame grabbing code... But this should serve you well enough i hope.

ZacDiggum commented 8 years ago

Hm, well I need an infinite (free run) loop. cam.grab_images(-1) seems to do that. But how to stop that loop, e.g. for changing parameters? I put this into class Camera in factory.pyx:

def stop_grabbing(self):
    self.camera.StopGrabbing()

and added this to cppclass CInstantCamera in pylon_def.pxd: void StopGrabbing except + It compiles with the changes but in Python cam.stop_grabbing() doesn't seem to break the frame grabbing loop. How do you implement a (stoppable) free run loop in your code? Could you give an example? Please?