Saving Images in own Thread

Hi Forum,

a customer came up on me with a question that seemed easy, however I am struggling with the answer.
As the customer acquires images from 8 cameras and wants to save the acquired images on his computer I suggested to him to do this in a new Thread for every image and store the threads in a Vector to make sure all images were written bevore exiting.
He gets the Image out of the WaitResult after calling WaitFor().
The question now is, as the image in WaitResult is a pointer, can he pass it to another thread without having to worry, that this image might be overwritten?
How will the Ringbuffer notice if the Image is saved, as this happens in another Thread.
Should he simply generate a copy to pass on?

Thank you in advance
Cheers
Chris

Hi @Chris,

you can pass the RingBufferImage pointer to a worker thread after acquisition.
However, by default the buffer might be overwritten in the background.
Because the buffer is returned to the queue of unlocked buffers once the next image is returned from wait(). This is usually not desired. However, if the ring buffer is large enough this is very unlikely to happen.

Anyway you should play safe by setting RingbufferLockmode::On! Now, only if last shared pointer to the image is released the buffer will return to the queue of unlocked buffers and can be filled with new image data. As a result you may get LostLocked images if you do not release the images pointers in time.

Please also note, that parallelise files access on multiple cores will usually not give you better performance as the HD is the common bottleneck!

2 Likes

Hi Andreas,

thank you for your answer, the LockMode::ON was in my mind as well but I was hoping there is a way to avoid this.

The performance of writing the images to the HD might not get faster, BUT the customer currently sees drops in the acquisition frame rate as he only acquires new images after the old one was saved.
I think we can avoid that by parallelising the process of saving the images.
If I am wrong on this one please let me know.

Thank you for you fast answer, I will forward this!

Cheers
Chris

I see, but he should be aware that he is not measuring acquisition frame rate but acquisition frame rate + save rate. In order to measure only acquisition multiple threads are an option.

Also keep in mind that different file formats come at hugely different cost when it comes to saving: Different Performance when Saving different Formats