genicam / harvesters

Image Acquisition Library for GenICam-based Machine Vision System
Apache License 2.0
502 stars 86 forks source link

Best practice for stopping a triggered camera #267

Closed danigamba closed 2 years ago

danigamba commented 2 years ago

Hello, I'm curious to know if there is a best practice for stopping a camera that is waiting the trigger. In the main thread we launch a second one that stops on

buffer = acq.fetch_buffer()

waiting for the camera aquiring a triggered frame of the next object. How could we stop this thread if the main tread needs to be stopped? Thank you

mahwhat commented 2 years ago

Hi @danigamba

I didn't quite understand your question, but I'll try to help you (I'm sorry if it's not the correct answer). For image acquisition I use two ways:

  1. For just one image:

    acq.start_acquisition()
    buffer = acq.fetch_buffer()
    acq.stop_acquisition()
  2. To run for a long period: I add a callback to NEW_BUFFER_AVAILABLE and use the acq.start_acquisition (run_in_background = True)

With that, I have the image acquisition happening in another thread without block my main thread.

kazunarikudo commented 2 years ago

@mahwhat Hi Matheus, thank you for the help. Those are the right approaches to resolve the issue.

This is completely a side note, we can rewrite the above code as follows:

acq.start()
with acq.fetch() as buffer:
    # work with the buffer
acq.stop()

Or,

acq.start(run_as_thread=True)

(I've learned that I was too verbose. ;-))

kazunarikudo commented 2 years ago

@danigamba I'm closing this but please feel free to create another one or reopen if you faced an issue. Thanks, Kazunari.