Acquire from multiple devices with CVBpy

@Andreas thanks for the guides.

But Im wondering, how can you get the stream of two (or more) cameras in python?

I’ve already successfully connected two cameras in the common vision manager, however using your example code I can only get the stream from the first camera.

Thanks.

Hi @RBirkeland,

just use the optional parameters for open:

device = cvb.DeviceFactory.open("GenICam.vin", port = 1)

This will open the second configured port.

An equivalent call would be:

device = cvb.DeviceFactory.open_port("GenICam.vin", 1)

Please also note, that you cannot acquire images from more than one device asynchronously.
This is due to the GIL (global interpreter lock), which does not allow real parallel execution. As a consequence the interpreter and all python threads block during a stream.wait() and cannot continue execution until this call returns.
Currently, you must synchronize (e.g. via hardware trigger) all your cameras to acquire safely from multiple streams.

I’m currently working on a solution that offers true asynchronous acquisition through native threads. As soon as it is available I will introduce it in Getting Started with CVBpy.

2 Likes

hi,
i try to grab images from two cameras in two separate processes.
in Process 1 i use:

device = cvb.DeviceFactory.open(os.path.join(cvb.install_path(), “drivers”, “GenICam.vin”), port=0)

in Process 2 i use:

device = cvb.DeviceFactory.open(os.path.join(cvb.install_path(), “drivers”, “GenICam.vin”), port=1)

but i allways get an error by start second process:

device = cvb.DeviceFactory.open(os.path.join(cvb.install_path(), “drivers”, “GenICam.vin”), port=1)
RuntimeError: {C-API call failed} ({LoadImageFileW})

if i has only one process, i can access to cam1 by port 1 or cam 2 by port 2, but i can’t access both at same time! why?

Hi,
accessing the second (1) port loads the device at port 0 and then shifts the port to 1. You would need to change the order in which you open the devices. So first loading port 1 and then 0 should fix the problem.

so easy? i will try it tomorrow

so i simple do:

device_A = cvb.DeviceFactory.open(os.path.join(cvb.install_path(), “drivers”, “GenICam.vin”), port=1)
device_B = cvb.DeviceFactory.open(os.path.join(cvb.install_path(), “drivers”, “GenICam.vin”), port=0)

thank you!

Hi,
i fixed the problem.

  • changing ports didn’t helped
  • behind start of first multiprocess time.sleep(5) waiting for finishing first connecting helped to connect to both cameras.
1 Like

To work around that problem we added the device discovery. This doesn’t use the GenICam.ini anymore. This only opens the device you want not interfering with other processes.

https://forum.commonvisionblox.com/t/discover-camera-and-check-this-connection-state/536/4?u=parsd