3

I'd like to capture an image at a specified shutter speed and ISO, and write it to disk. I thought that'd be pretty straightforward but... apparently not? In searching, I found people complaining of the same thing 2 years ago but no answers... I guess I'm hoping something has changed.

import picamera
import time
from fractions import Fraction

start = time.time()
print "Initializing...",
camera = picamera.PiCamera()
camera.resolution = (2592,1944)
camera.awb_mode = 'sunlight'
camera.framerate = Fraction(1,15)
camera.exposure_mode = 'off'
camera.iso = 800
camera.shutter_speed = 6000000
print "Done! ",
stop = time.time()
print (stop-start), "seconds"

for i in range(0,10):
    start = time.time()
    print "capturing...",
    camera.capture('image.jpg', format='jpeg', quality=100)
    print "done  ",
    stop = time.time()
    print (stop-start), "seconds"

Initialization takes 0.59 seconds, fine no problem
First image takes 37.44 seconds
The rest take 24.9 seconds each

I'm fine with a bit of overhead, but the overhead is 3 times as long as the actual exposure! Any way around this? Or even an explanation of what's happening for the half-minute it's not taking the picture?

MattieShoes
  • 31
  • 1
  • 2

1 Answers1

1

First up, you should profile your code, probably using cProfile:

https://docs.python.org/2/library/profile.html

Optimization without knowing where the time is spent is often pointless.

If the problem is mainly time to write to disk, you might try capturing to a stream/buffer, and then writing the buffer to disk with a side-process, perhaps using threading or an entire separate process which you pass the data to. This article describes how to capture to a stream:

http://picamera.readthedocs.org/en/latest/recipes1.html

This article describes how to use threading easily with the 'threading' library:

http://pymotw.com/2/threading/

Should be pretty easy, since you basically just want to fire off a thread to write data to a specified file each time the image capture is done...

sdenton4
  • 371
  • 2
  • 4