picamera2 icon indicating copy to clipboard operation
picamera2 copied to clipboard

Adds example for overlay_png

Open MazrimT opened this issue 1 year ago • 3 comments

Just an example file with how you can add a "overlay" of a png file to a video as discussed in issue https://github.com/raspberrypi/picamera2/issues/913

MazrimT avatar Jan 11 '24 22:01 MazrimT

Hi, thanks for this example, I think it looks good - and thank you for taking the time to create a new example for us!

One slight misgiving I have is that it's loading the new overlay (i.e. doing filesystem and decompression activity) in the pre_callback, which runs in the camera thread. Mostly I try to discourage this as it increases the risk of dropping camera frames.

I wonder whether if would be worth using a separate thread which just sits there in the background and updates the overlay_png at the correct moment, and the pre_callback, running asynchronously to this, simply "samples" the most recently loaded one. Any resizing of the overlay could in principle be done outside the camera thread, too. What do you think?

davidplowman avatar Jan 12 '24 09:01 davidplowman

@davidplowman That is a great idea, I updated to do just that.

MazrimT avatar Jan 12 '24 21:01 MazrimT

Thanks for the update - could you maybe squash the 3 commits into a single one? I always think that in a public repo it doesn't usually help other users to "see the development process"! If you haven't done so, could you ensure the commit is signed-off according to the guidelines.

I had one final thing that I thought might be worth investigating

I was wondering a little bit whether we should try to combine the overlay using cv2.addWeighted. It might do all the alpha blending for us (so no need to handle the alpha channel separately). It might also give us better performance - quite a few OpenCV functions are good about using multiple threads on images to speed things up.

But let me know what you want to do on that. Thanks again!

davidplowman avatar Jan 15 '24 10:01 davidplowman