Created
September 11, 2016 09:33
-
-
Save waveform80/7a0ca251d1c352b594c18ffb36db2588 to your computer and use it in GitHub Desktop.
A little script for testing what happens when you fiddle with the Pi camera module's gains and shutter speed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import ( | |
unicode_literals, | |
absolute_import, | |
print_function, | |
division, | |
) | |
str = type('') | |
from picamera import PiCamera | |
import curses | |
def main(window): | |
window.nodelay(True) | |
camera = PiCamera(resolution='VGA', framerate=30) | |
camera.start_preview() | |
while True: | |
window.addstr(0, 0, 'Analog gain: %-8.3fx' % camera.analog_gain) | |
window.addstr(1, 0, 'Digital gain: %-8.3fx' % camera.digital_gain) | |
window.addstr(2, 0, 'Exposure mode: %-5s' % ('fixed' if camera.exposure_mode == 'off' else 'auto')) | |
window.addstr(3, 0, 'ISO: %-5d' % camera.iso) | |
window.addstr(4, 0, 'Shutter speed: %-10.3fms' % (camera.exposure_speed / 1000)) | |
window.addstr(5, 0, 'Shutter mode: %-5s' % ('fixed' if camera.shutter_speed != 0 else 'auto')) | |
window.addstr(7, 0, '1 = Set ISO 100') | |
window.addstr(8, 0, '2 = Set ISO 200') | |
window.addstr(9, 0, '4 = Set ISO 400') | |
window.addstr(10, 0, '8 = Set ISO 800') | |
window.addstr(11, 0, '+ = Increase shutter time') | |
window.addstr(12, 0, '- = Decrease shutter time') | |
window.addstr(13, 0, '0 = Auto shutter time') | |
window.addstr(14, 0, 'A = Toggle AGC') | |
window.addstr(16, 0, 'Q = Quit') | |
window.refresh() | |
try: | |
key = window.getkey() | |
except curses.error: | |
continue | |
else: | |
if key in '1248': | |
camera.iso = { | |
'1': 100, | |
'2': 200, | |
'4': 400, | |
'8': 800, | |
}[key] | |
elif key in 'aA': | |
camera.exposure_mode = 'auto' if camera.exposure_mode == 'off' else 'off' | |
elif key == '0': | |
camera.shutter_speed = 0 | |
elif key == '+': | |
camera.shutter_speed = min(1000000, camera.exposure_speed + 100) | |
elif key == '-': | |
camera.shutter_speed = max(1, camera.exposure_speed - 100) | |
elif key in 'qQ': | |
break | |
curses.wrapper(main) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
SSH into your Pi and run the script from there, so you can see the controls and the preview at the same time. If you haven't got a spare machine to SSH from, add something like
alpha=192
to thestart_preview()
call so you can see the controls. Now, fiddle!