VimbaPython
VimbaPython copied to clipboard
async acquisition not
I'm currently adapting a GUI to work with an Allied Vision camera, and trying to use async acquisition for returning a continuous feed of images. The examples seem simple enough, but I can't get the handler to be called by 'start_streaming'
right now I have the following:
def async_handler(self, cam, frame):
if frame.get_status() == FrameStatus.Complete:
print('{} acquired {}'.format(cam, frame), flush=True)
frame.convert_pixel_format(PixelFormat.Rgb8)
self.raw_frame = frame.as_numpy_ndarray()
else:
print('no frame yet')
cam.queue_frame(frame)
def start_stream(self):
print('start')
with Vimba.get_instance() as vimba:
print('vimba')
with self.camera:
print(self.camera)
print(self.camera.is_streaming())
self.camera.start_streaming(handler=self.async_handler)
print(self.camera.is_streaming())
print('over')
where 'self.camera' is a stored camera id ("Camera(id=DEV_000F31036CB8)"). For some reason, it doesn't seem like 'async_handler' is called at all
I've also played with the synchronous acquisition, and the below works fine with no issues, but I would like faster updates with the async acquisition
def acquire_frame(self):
with Vimba.get_instance() as vimba:
with self.camera:
for frame in self.camera.get_frame_generator(limit=1, timeout_ms=100):
print('Got {}'.format(frame), flush=True)
frame.convert_pixel_format(PixelFormat.Rgb8)
self.raw_frame = frame.as_numpy_ndarray()
print(frame.get_pixel_format())
It appears that once you start the asynchronous acquisition, you do not give the main thread anything else to do. This means that after start_streaming is called, your code will immediately continue with the two print statements and then leave the with context that opened the camera connection. When that happens the camera connection is closed, which in turn stops the image acquisition. I believe all this happens so quickly, that your camera does not have any time to actually submit any frames.
In our asynchronous_grab.py example we are calling input() to wait for the user to press enter. The main thread is blocked until that function returns, allowing the camera to submit frames while the main thread waits.
In the more complex multithreading_opencv.py example the main thread waits for the consumer to finish, which happens when the user presses a certain key (in this case
You would need a similar approach in your code. Maybe adding a call to input() is a good first start but I assume that you will likely want to have some more flexible way to signal that acquisition should be stopped. Generally I would recommend using pythons threading.Event object for that. It provides a convenient wait() method, that halts execution until the event is set() by another thread.
Hi, just wanted to write back that this was very helpful! Still have some issues with speed (will open another thread later once I try some more stuff).
Thank you! Alan