genicam / harvesters

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

Clear camera buffer #383

Open MasIgor opened 1 year ago

MasIgor commented 1 year ago

Hello!

is there a way to clear the camera buffer? when I try to fetch the buffer, I am expecting it to have just been triggered, thus returning a image of the current state in front of the camera. there are situations where the camera gets hardware triggerd without me knowing, and the image returned is the one from the buffer that has been taken some time earlier. I would like to clear the buffer a second before i KNOW a trigger to be set, so right after the trigger the image will for sure be the correct one.

Is this possible? Any help is greatly apprecaited..

Thank you!

best regards

Neurolearn-Daniel commented 1 year ago

I'm having a similar issue.

I am not triggering the camera from external sources. Here is a snippet of my camera trigger callback:

def fetch_image(self):
    try:
        with self.image_acquirer.fetch() as buffer:
            image = buffer_to_arr(buffer)
            return np.array(image, copy=True).astype(np.uint8)

    except TimeoutException as e:
        self.logger_callback(f'Failed to acquire image: \n{e}')

A few images are old.

Some notes: I am running the arm64 version of Harvester. image_acquirer.buffer_handling_mode = 'NewestOnly' is used

MasIgor commented 1 year ago

@Neurolearn-Daniel for now I solved it like this, but its not clearing the buffer:

            self.ia.buffer_handling_mode = 'NewestOnly'
            self.ia.num_buffers = 1
Neurolearn-Daniel commented 1 year ago

Thanks @tanzerlana and sorry for the very late reply, I've been away from work during the holidays. Your suggestion did not solve my issue. But I have since solved it.

First I set the following camera parameters:

ia.remote_device.node_map.AcquisitionMode.value = "Continuous" 
ia.remote_device.node_map.TriggerSelector.value = 'FrameStart' 
ia.remote_device.node_map.TriggerActivation.value = 'RisingEdge'
ia.remote_device.node_map.TriggerMode.value = 'On'
ia.remote_device.node_map.TriggerSource.value = 'Software'

Then to capture an image:

ia.remote_device.node_map.TriggerSoftware.execute()
with ia.fetch() as buffer:
    # use buffer

This may not help you as you are using hardware triggers.