I'm currently writing a python script which needs to capture an image. I'm currently using PiCamera.capture()
to accomplish this, but it takes too long to capture images. The project requires as high of a resolution as possible, so I cannot reduce the resolution below the max of 2592x1944 (for my current camera module).
This script shows the issue with PiCamera.capture()
:
import time
from picamera import PiCamera
from io import BytesIO
cam = PiCamera()
start = time.time()
cam.start_preview()
print("preview start:", time.time() - start, "seconds")
2592x1944 test
cam.resolution = (2592, 1944)
time.sleep(2) # give it time to change resolution
start = time.time()
cam.capture("test-2592x1944.png")
print("2592x1944 capture:", time.time() - start, "seconds")
640x480 test
cam.resolution = (640, 480)
time.sleep(2) # give it time to change resolution
start = time.time()
cam.capture("test-640x480.png")
print(" 640x480 capture:", time.time() - start, "seconds")
2592x1944 test with IO stream
cam.resolution = (2592, 1944)
time.sleep(2) # give it time to change resolution
my_stream = BytesIO()
start = time.time()
cam.capture(my_stream, "png")
print("2592x1944 capture with stream:", time.time() - start, "seconds")
It gives the following output:
preview start: 0.017431259155273438 seconds
2592x1944 capture: 13.869317054748535 seconds
640x480 capture: 1.24507474899292 seconds
2592x1944 capture with stream: 13.91780948638916 seconds
I don't mind a capture taking a few seconds, but over 13 seconds is too long. Capturing to a stream instead of a file doesn't help either, as you can see. How can I reduce the time of capturing without reducing the resolution, either within the PiCamera library or outside it?
Addressing why this shouldn't be closed as duplicate
I'm aware of two questions which ask similar questions. This question is not answered by them for the following reasons:
- Why does PiCamera take so long to capture?: There is one answer here, which doesn't answer the question sufficiently. It suggests using an IO stream and thread to avoid time for writing to disk, but I've shown above that this doesn't contribute significantly to the long delay.
- How to reduce capturing time in raspberry pi camera? [duplicate]: This one was unanswered and closed as a duplicate to the one linked above.