alliedvision / VimbaPython

Old Allied Vision Vimba Python API. The successor to this API is VmbPy
BSD 2-Clause "Simplified" License
93 stars 40 forks source link

Grab Frames with Hardware Trigger #145

Closed Atotem closed 1 year ago

Atotem commented 1 year ago

I have been trying to understand how the settings should be in order to get the actual frame when the camera is triggered by a Hardware trigger, however, I haven't manage to truly understand. I tried first setting the camera in 'Single Frame' in the Vimba Viewer, but the software only captures 1 frame when the camera is triggered. So technically, in order to get 1 frame each time the camera is triggered once, I should turn 'off' and then 'on' the Acquisition Status. In the other hand, when I try with 'Continuous' mode, I receive way more frames than the ones I actually need. To prove this observation I run a script based on the official documentation.

from vimba import *
from datetime import datetime

camera_id = '' # Add camera ID

def frame_handler(cam: Camera, frame: Frame):
    if frame.get_status() == FrameStatus.Complete:
        print('Frame(ID: {}) has been received.'.format(frame.get_id()), flush=True)
        print(datetime.now())

    cam.queue_frame(frame)

def main():

    with Vimba.get_instance() as vimba:

        cam = vimba.get_camera_by_id(camera_id)

        with cam:
            cam.LineSelector.set('Line0')
            cam.LineMode.set('Input')
            cam.TriggerSource.set('Line0')
            cam.TriggerSelector.set('FrameStart')
            cam.TriggerActivation.set('RisingEdge')
            cam.TriggerMode.set('On')
            # cam.AcquisitionMode.set('SingleFrame')
            cam.AcquisitionMode.set('Continuous')
            try:
                cam.start_streaming(handler=frame_handler)

                print("waiting for triggers...")
                input()
            finally:
                cam.stop_streaming ()

if __name__ == '__main__':
    main()

The camera is being triggered with an Arduino UNO, and the model of the camera is Alvium 1800 U-2050m. When I run this script and compare the output with output from Arduino IDE, I get that I'm obtaining more frames. Even before the camera is triggered. I check with a multimeter if the cables are working properly and if the Arduino is really triggering when it's suppose to trigger, and my conclusions were that the hardware is not the problem.

Terminal after running the python script:

waiting for triggers...
Frame(ID: 0) has been received.
2023-01-31 13:45:20.927649
Frame(ID: 1) has been received.
2023-01-31 13:45:22.156585
Frame(ID: 2) has been received.
2023-01-31 13:45:22.527142
Frame(ID: 3) has been received.
2023-01-31 13:45:23.815994
Frame(ID: 4) has been received.
2023-01-31 13:45:26.794859
Frame(ID: 5) has been received.
2023-01-31 13:45:27.085129
Frame(ID: 6) has been received.
2023-01-31 13:45:29.222677
Frame(ID: 7) has been received.
2023-01-31 13:45:29.964611
Frame(ID: 8) has been received.
2023-01-31 13:45:30.637258

Serial Monitor from Arduino.

13:45:29.779 -> TRIGGER FIRED

I checked and this also happens with the software. More than 1 frame is capture even if the camera is not triggered. What can be causing the problem? I thank you in advance for every comment or suggestion.

Teresa-AlliedVision commented 1 year ago

Hello Atotem, your settings and code look correct. Did you check if all of the commands return a success? This looks as if TriggerMode is still set to Off. If for example you have AquisitionFrameRateEnable set to true, then the trigger mode can't be set to On. See if you can do the settings in Vimba Viewer and if you can get the frames there. The GUI of the viewer will show you if you are able to set the features.

Atotem commented 1 year ago

Hello @Teresa-AlliedVision,

I have been running several tests and apparently somehow the motor is triggering the camera, even when the camera is connected to a cable connected to nothing. If there are some tips to consider I would greatly appreciate it. I will let you know if I fix it.

Teresa-AlliedVision commented 1 year ago

Hello Atotem, what Motor are you referring to and what cable specifically is connected to nothing? Can you post a screenshot of your settings in Vimba Viewer? The Coutner on the bottom of the screen will also show how many frames arrive.