waveform80 / picamera

A pure Python interface to the Raspberry Pi camera module
https://picamera.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
1.57k stars 356 forks source link

use of resize with capture_sequence appears to result in duplicate images? #433

Open pootle opened 7 years ago

pootle commented 7 years ago

I'm using capture_sequence with a home rolled iterator to do timelapse style stills. - I put a delay in the iterator to hold off until the next tick. I also in some circumstances use resize to reduce the file sizes and consequent processing / network bandwidth (I'm shipping the images out to a network file share in a separate python process) I noticed I was getting pairs of identical images, and after a few different tests I found that turning off the resize stopped the duplication. I added some tracking around the yield statement in the iterator and noticed that with resize on, every other yield returned in < 1/10th second,, normally it takes 4 - 5 seconds.

I'm running with a tick of 8 seconds, so the normal delay is 3 - 4 seconds. I'm running on a Pi Zero,

I've tested with rgb format as well and the same thing happens.

These are the params to capture_sequence when it is OK:

{'burst': False, 'bayer': False, 'quality': 95, 'thumbnail': None, 'format': 'jpeg'}

and with duplicate images:

{'quality': 95, 'thumbnail': None, 'bayer': False, 'burst': False, 'resize': (1640, 1232), 'format': 'jpeg'} log.txt

6by9 commented 5 years ago

I suspect one of two things is happening.

a) This is a pipeline. You're stalling the pipeline by starving it of buffers at the very end. If resize is in the pipeline then the camera->resize buffer is free for reuse after the capture and will therefore be filled. When you release the resize output buffer it only needs to do the final resize of the image rather than take the capture.

b) The handling of the output buffers from resize is wrong. Typically on a stills capture it will generate a buffer with the data, and then an empty buffer with an EOS (End Of Stream) flag. It may be saving the contents of that buffer a second time.