Hi all!
I found that the camera sometimes get’s stuck in acquistion mode, if not aborted correctly.
I added two scripts below that can be used to reproduce the problem (one for the basic acquisition, one for parallel). The steps I execute (for either script):
- Start the script, wait until you receive at least an image
- Before the scripts finishes, terminate it
- Start the script again, and wait for the first image
Step 3 will run indefintly and never receive an image (it also doesnt throw an error), however we can find the device, and connect to it. I have tried to abort/terminate the stream after opening the device in the second run, but this didn’t work. The only way I found to solve this, was by going to genicam-> open the device-> stop the acquisition.
I would like to check, and if needed, terminate the acquistion from within python upon opening the devices, so that I’m sure the acquisition will run properly and the code won’t get stuck.
We are using multiple GO-5000M-PGE (usb3)
What would be the proper approach? Thx in advance!
Basic Script
import cvb
import time
# ----------------- Acquire Device ----------------
def get_device_list():
discovered_device_list = cvb.DeviceFactory.discover_from_root(flags=cvb.DiscoverFlags.IgnoreVins)
if discovered_device_list is None or len(discovered_device_list) == 0:
raise RuntimeError("unable to find any devices. Is any other program using the cameras?")
return discovered_device_list
device_list = get_device_list()
device = device_list[0] # gets the first device
# ---------------- Do Acquisition ------------------------
with cvb.DeviceFactory.open(device.access_token) as device:
stream = device.stream
stream.start()
#range is high, so you have time to press the stop button
for i in range(100):
image, status = stream.wait()
if status == cvb.WaitStatus.Ok:
print("Acquired image: " + str(i))
#time.sleep(3)
#raise Exception('random exception to stop the process')
stream.abort()
Parallel Script
import time
import os
import cvb
class MyStreamHandler(cvb.SingleStreamHandler):
def __init__(self, stream):
super().__init__(stream)
self.rate_counter = cvb.RateCounter()
# called in the interpreter thread to setup additionla stuff.
def setup(self, stream):
super().setup(stream)
print("setup")
# called in the interpreter thread to tear down stuff from setup.
def tear_down(self, stream):
super().tear_down(stream)
print("tear_down")
# called from the aqusition thread
def handle_async_stream(self, stream):
super().handle_async_stream(stream)
print("handle_async_stream")
# called from the aqusition thread
def handle_async_wait_result(self, image, status):
super().handle_async_wait_result(image, status)
self.rate_counter.step()
print("New image: " + image.__class__.__name__ + " " + str(image) + " | Status: " + str(status) + " | Buffer Index: " + str(image.buffer_index))
# print messurement results
def eval(self):
print("Acquired with: " + str(self.rate_counter.rate) + " fps")
def get_device_list():
discovered_device_list = cvb.DeviceFactory.discover_from_root(flags=cvb.DiscoverFlags.IgnoreVins)
if discovered_device_list is None or len(discovered_device_list) == 0:
raise RuntimeError("unable to find any devices. Is any other program using the cameras?")
return discovered_device_list
device_list = get_device_list()
device = device_list[0] # gets the first device
with cvb.DeviceFactory.open(device.access_token) as device:
with MyStreamHandler(device.stream) as handler:
handler.run()
time.sleep(4)
handler.finish()