basler / pypylon

The official python wrapper for the pylon Camera Software Suite
http://www.baslerweb.com
BSD 3-Clause "New" or "Revised" License
567 stars 207 forks source link

Synchronously acquire images with multiple cameras #470

Open sarperkilic opened 2 years ago

sarperkilic commented 2 years ago

Hello eveyone,

I am using pypylon to take images from my application.

I will use 2 cameras and I need to grab images synchronously.

When I have a look to grabmultiplecameras sample, It says thay hardware trigger setup can be used to cause all cameras to grab images synchronously. According to their default configuration, the cameras are set up for free-running continuous acquisition.

Can I do this from pypylon? Or I have to do this on pylon viewer?

I am little bit lost about grabbing multiple images from multiple cameras synchronously from my pypylon script.

Detailed suggestions will be extremely useful for me.

Thanks

thiesmoeller commented 2 years ago

Hi @sarperkilic,

Please check our companion repository https://github.com/basler/pypylon-samples , where you'll find samples/notebooks both for multi camera and hardware trigger.

As an overall statement to high precision syncing of cameras:

U3V: hardware GEV: hardware, action command, ieee1588 synchronized freerun

sarperkilic commented 2 years ago

Hi @sarperkilic,

Please check our companion repository https://github.com/basler/pypylon-samples , where you'll find samples/notebooks both for multi camera and hardware trigger.

As an overall statement to high precision syncing of cameras:

U3V: hardware GEV: hardware, action command, ieee1588 synchronized freerun

Hello again @thiesmoeller,

I need your help about this topic.

We want to take images by triggering two Basler color cameras synchronously.

We will do the triggering using pypylon.

When we connect two cameras to an industrial computer with a USB 3.0 port without the need for any additional cards (without an extra frame grabber GigE card), will we be able to run these cameras synchronously with a software trigger?

Are there any disadvantages of triggering with software trigger?

Are there any disadvantages to using USB 3.0 instead of GigE?

Are there any disadvantages to using the computer's USB 3.0 ports instead of the USB 3.0 Interface Card?

In other words, will it be technically possible for us to provide simultaneous software triggers, take pictures of two cameras at the same time, and transmit the pictures they took to the computer simultaneously?

Thanks in advance for your answers, if you need additional information, please let me know.

thiesmoeller commented 2 years ago

When we connect two cameras to an industrial computer with a USB 3.0 port without the need for any additional cards (without an extra frame grabber GigE card), will we be able to run these cameras synchronously with a software trigger?

On USB 3.0 you'll always have point-to-point communication. So you can only send the software triggers one after the other. This will give a typical delay of 500µs to a 1ms, but could be worse, if your operating system halts your process for longer .... Depending on your realtime requirements, this could be sufficient .... You have to check this

Are there any disadvantages of triggering with software trigger?

Software trigger always has your host and it's operating system in the game. So a lot of components, that you don't control..

Are there any disadvantages to using USB 3.0 instead of GigE?

GigE allows for easier synchronization ( ActionCMD and IEEE1588 ) USB3 allows for higher Bandwidth....

Are there any disadvantages to using the computer's USB 3.0 ports instead of the USB 3.0 Interface Card?

There is absolutely no difference in timing ( both are PCIe devices ) But computers USB3 ports on e.g. Intel have higher accumulated bandwidth, than an external multiport card.

In other words, will it be technically possible for us to provide simultaneous software triggers, take pictures of two cameras at the same time, and transmit the pictures they took to the computer simultaneously?

On USB3.0: If you mean with "simultaneously" no timing difference between the devices, the answer is no. This is only reachable with a HW trigger.

For HW Trigger, you can also use one of the cameras as "main-camera" and trigger the others from the first camera`s timing. You just have to wire up the IO-Ports of the cameras Or use the UserOutput of one camera to trigger itself and the other ones.

FlorentLM commented 2 years ago

Hi,

Sorry to hijack this issue.

I have a somewhat dumb question on the subject as I have very bad electrical knowledge: @thiesmoeller Would you have an example schematic for simultaneously triggering multiple cameras with, say an Arduino or a RPi? Can you just branch all cameras off the same 5V line? Or do you have to have a main camera and the rest as slaves?

jhacsonmeza commented 2 years ago

Hi @FlorentLM You need to use the signal from your Arduino/RPi as input to all your cameras. This means that all your cameras must be connected to the same 5V output line from your Arduino and also to the same ground. You don't have a kind of main camera, because the signal is going to trigger all the cameras simultaneously. Off course, you need to enable the external trigger option in all your cameras for it to work. I don't know if you will do this in code or with the GUI.

thiesmoeller commented 2 years ago

@FlorentLM and @jhacsonmeza check the manual for details: e.g. on a Basler ace USB: schematics for trigger circuit: https://docs.baslerweb.com/circuit-diagrams-%28ace%29.html#gpio-input-line electrical spec: https://docs.baslerweb.com/aca2000-165um.html#operation-as-input

Regarding multiple cameras: check the max sink current of your arduino/rpi with the number of cameras you want to connect. e.g. Basler ace USB specifies a max sink current on GPIO input of 2mA. if your arduino/rpi e.g. has a limit of 16mA you could trigger up to eight cameras from a single gpio. If you have to trigger more cameras , you have to use an external buffer to support the higher load.

FlorentLM commented 2 years ago

@thiesmoeller, @jhacsonmeza - Thanks both, it works :)

aruna-ram commented 2 years ago

@thiesmoeller I'm trying to frame synchronise two cameras. I'm generating a square wave signal to one raspberry pi gpio pin. This will be the FrameStart trigger. My current issue is sending this wave to two gpio pins simultaneously, one pin for each camera. I haven't found a way to do this (from current searches and basic electronics knowledge...).

On USB3.0: If you mean with "simultaneously" no timing difference between the devices, the answer is no. This is only reachable with a HW trigger.

For HW Trigger, you can also use one of the cameras as "main-camera" and trigger the others from the first camera`s timing. You just have to wire up the IO-Ports of the cameras Or use the UserOutput of one camera to trigger itself and the other ones.

In your last sentence, do you mean that we could connect the Arduino to one camera (Camera 1) and then set its User Output feature to follow the trigger signal and transmit this to the next camera, like in the attached figure. This would solve the problem of generating the same signal on multiple GPIO pins. Would this method be synchronous - i.e. no timing difference between devices?

Screenshot 2022-07-07 at 17 14 09

Thanks in advance!

thiesmoeller commented 2 years ago

You can just connect the same arduino pin to both cameras in parallel to both cameras.

On a standard arduino uno the GPIO can source and sink 20mA ( https://docs.arduino.cc/hardware/uno-rev3 ) So you would be able to connect up to 10 cameras directly ( we sink 2mA )

aruna-ram commented 2 years ago

Thanks @thiesmoeller! Just to doublecheck, I'll try wiring it up like the figure below using a breadboard :)

Screenshot 2022-07-07 at 18 16 13
jhacsonmeza commented 2 years ago

@aruna-ram I hope this example can help. schematic

aruna-ram commented 2 years ago

@jhacsonmeza Yes it really does, thank you very much!

thiesmoeller commented 2 years ago

and in schematic form: image