class GPhotoTestCase(unittest.TestCase): def setUp(self): self._test_subprocess = FakeSubprocess() self._gphoto = GPhoto(self._test_subprocess) def tearDown(self): pass def test_set_shutter_speed(self): popen = FakePopen( 'Label: Shutter Speed\nType: MENU\nCurrent: 30\nChoice: 0 Bulb\nChoice: 4 2', '', 0) self._test_subprocess.set_Popen_for_cmd( 'gphoto2 --get-config /main/settings/shutterspeed', popen) self._gphoto.set_shutter_speed(secs="2") assert ['gphoto2 --get-config /main/settings/shutterspeed' ] in self._test_subprocess.get_invocations() assert ['gphoto2 --set-config /main/settings/shutterspeed=4' ] in self._test_subprocess.get_invocations() def test_get_camera_time(self): data = ''.join(file('testdata/datetime', 'r').readlines()) popen = FakePopen(data, '', 0) self._test_subprocess.set_Popen_for_cmd( 'gphoto2 --get-config /main/status/datetime', popen) tim = self._gphoto.get_camera_date_time() assert time.strptime("2013-01-10 07:16:59", "%Y-%m-%d %H:%M:%S") == tim
def test_configs(): camera = GPhoto(subprocess) for config in CONFIGS: camera.set_shutter_speed(secs=config[0]) camera.set_iso(iso=str(config[1])) time.sleep(1)
def main(): #print "Testing Configs" #test_configs() print "Timelapse" camera = GPhoto(subprocess) idy = Identify(subprocess) netinfo = NetworkInfo(subprocess) #ui = TimelapseUi() current_config = 11 ## <-- set this manually because we don't have an LCD to select it shot = 0 prev_acquired = None last_acquired = None last_started = None network_status = netinfo.network_status() #current_config = ui.main(CONFIGS, current_config, network_status) try: while True: last_started = datetime.now() config = CONFIGS[current_config] print "Shot: %d Shutter: %s ISO: %d" % (shot, config[0], config[1]) #ui.backlight_on() #ui.show_status(shot, CONFIGS, current_config) camera.set_shutter_speed(secs=config[0]) camera.set_iso(iso=str(config[1])) #ui.backlight_off() try: filename = camera.capture_image_and_download() except Exception, e: print "Error on capture." + str(e) print "Retrying..." # Occasionally, capture can fail but retries will be successful. continue prev_acquired = last_acquired brightness = float(idy.mean_brightness(filename)) last_acquired = datetime.now() print "-> %s %s" % (filename, brightness) if brightness < MIN_BRIGHTNESS and current_config < len( CONFIGS) - 1: current_config = current_config + 1 elif brightness > MAX_BRIGHTNESS and current_config > 0: current_config = current_config - 1 else: if last_started and last_acquired and last_acquired - last_started < MIN_INTER_SHOT_DELAY_SECONDS: print "Sleeping for %s" % str( MIN_INTER_SHOT_DELAY_SECONDS - (last_acquired - last_started)) time.sleep((MIN_INTER_SHOT_DELAY_SECONDS - (last_acquired - last_started)).seconds) shot = shot + 1 except Exception, e: print "Error:", str(e)
def main(): #print "Testing Configs" #test_configs() timestr=str(datetime.now()) print "No problem. Timelapse starts now, at " + timestr camera = GPhoto(subprocess) idy = Identify(subprocess) netinfo = NetworkInfo(subprocess) #ui = TimelapseUi() current_config = 28 shot = 0 prev_acquired = None last_acquired = None last_started = None #network_status = netinfo.network_status() #current_config = ui.main(CONFIGS, current_config, network_status) try: while True: last_started = datetime.now() config = CONFIGS[current_config] print "Shot: %d Shutter: %s ISO: %d" % (shot, config[0], config[1]) #ui.backlight_on() #ui.show_status(shot, CONFIGS, current_config) camera.set_shutter_speed(secs=config[0]) camera.set_iso(iso=str(config[1])) #ui.backlight_off() try: filename = camera.capture_image_and_download(shot) print "Capture signaled." except Exception, e: print "Error on capture." + str(e) print "Retrying..." # Occasionally, capture can fail but retries will be successful. continue prev_acquired = last_acquired brightness = float(idy.mean_brightness(filename)) last_acquired = datetime.now() print "-> %s Brightness: %s" % (filename, brightness) if brightness < MIN_BRIGHTNESS and current_config < len(CONFIGS) - 1: current_config = current_config + 1 print "WARNING: Brightness is below threshold " + strMIN_BRIGHTNESS + ", trying a brighter config NOW!" elif brightness > MAX_BRIGHTNESS and current_config > 0: print "WARNING: Brightness is above threshold " + strMAX_BRIGHTNESS + ", trying a darker config NOW!" else: if last_started and last_acquired and last_acquired - last_started < MIN_INTER_SHOT_DELAY_SECONDS: print "Sleeping for %s" % str(MIN_INTER_SHOT_DELAY_SECONDS - (last_acquired - last_started)) time.sleep((MIN_INTER_SHOT_DELAY_SECONDS - (last_acquired - last_started)).seconds) shot = shot + 1 except Exception,e: #ui.show_error(str(e)) print(str(e))
def test_configs(): camera = GPhoto(subprocess) for config in CONFIGS: print "testing camera setting: Shutter: %s ISO %d" % (config[1], config[3]) camera.set_shutter_speed(secs=config[1]) camera.set_iso(iso=str(config[3])) time.sleep(1)
def testConfigs(self): print("Testing Configs") camera = GPhoto(subprocess) for config in CONFIGS: print("Testing camera setting: Shutter: %s ISO %d" % (config[1], config[3])) camera.set_shutter_speed(secs=config[1]) camera.set_iso(iso=str(config[3])) time.sleep(SLEEP_TIME)
def main(): #print "Testing Configs" #test_configs() print "Timelapse" camera = GPhoto(subprocess) idy = Identify(subprocess) netinfo = NetworkInfo(subprocess) #ui = TimelapseUi() current_config = 11 ## <-- set this manually because we don't have an LCD to select it shot = 0 prev_acquired = None last_acquired = None last_started = None network_status = netinfo.network_status() #current_config = ui.main(CONFIGS, current_config, network_status) try: while True: last_started = datetime.now() config = CONFIGS[current_config] print "Shot: %d Shutter: %s ISO: %d" % (shot, config[0], config[1]) #ui.backlight_on() #ui.show_status(shot, CONFIGS, current_config) camera.set_shutter_speed(secs=config[0]) camera.set_iso(iso=str(config[1])) #ui.backlight_off() try: filename = camera.capture_image_and_download() except Exception, e: print "Error on capture." + str(e) print "Retrying..." # Occasionally, capture can fail but retries will be successful. continue prev_acquired = last_acquired brightness = float(idy.mean_brightness(filename)) last_acquired = datetime.now() print "-> %s %s" % (filename, brightness) if brightness < MIN_BRIGHTNESS and current_config < len(CONFIGS) - 1: current_config = current_config + 1 elif brightness > MAX_BRIGHTNESS and current_config > 0: current_config = current_config - 1 else: if last_started and last_acquired and last_acquired - last_started < MIN_INTER_SHOT_DELAY_SECONDS: print "Sleeping for %s" % str(MIN_INTER_SHOT_DELAY_SECONDS - (last_acquired - last_started)) time.sleep((MIN_INTER_SHOT_DELAY_SECONDS - (last_acquired - last_started)).seconds) shot = shot + 1 except Exception,e: print "Error:", str(e)
def testConfigs(): print "Testing Configs" camera = GPhoto(subprocess) for config in CONFIGS: print "Testing camera setting: Shutter: %s ISO %d" % (config[1], config[3]) camera.set_shutter_speed(secs=config[1]) camera.set_iso(iso=str(config[3])) time.sleep(SLEEP_TIME) lcd = Adafruit_CharLCDPlate() lcd.clear() lcd.backlight(lcd.TEAL)
def main(): print "Frizlapse" camera = GPhoto(subprocess) #idy = Identify(subprocess) #netinfo = NetworkInfo(subprocess) #network_status = netinfo.network_status() shot = 0 prev_acquired = None last_acquired = None last_started = None camera.set_shutter_speed(secs=CONFIG[0]) camera.set_iso(iso=str(CONFIG[1])) try: while True: print "Shot n. %d Shutter: %s ISO: %d" % (shot, CONFIG[0], CONFIG[1]) last_started = datetime.now() try: # Capture image filename = camera.capture_image_and_download(FOLDERPATH) except Exception, e: print "Error on capture." + str(e) print "Retrying..." # Occasionally, capture can fail but retries will be successful. continue prev_acquired = last_acquired last_acquired = datetime.now() if last_started and last_acquired and last_acquired - last_started < MIN_INTER_SHOT_DELAY_SECONDS: print "Sleeping for %s" % str(MIN_INTER_SHOT_DELAY_SECONDS - (last_acquired - last_started)) time.sleep((MIN_INTER_SHOT_DELAY_SECONDS - (last_acquired - last_started)).seconds) else: print "No need to sleep, we are late %s" % str((last_acquired - last_started) - MIN_INTER_SHOT_DELAY_SECONDS) shot = shot + 1 if shot == SHOTS: print "Picture sequence finished! " print "Starting video ... " # FFMPEG stuff print "Video %s finished " % str("filename.mp4") break except Exception,e: print "Exception " + str(e)
def main(): print "Timelapse" camera = GPhoto(subprocess) idy = Identify(subprocess) netinfo = NetworkInfo(subprocess) ui = TimelapseUi() current_config = 11 shot = 0 prev_acquired = None last_acquired = None last_started = None network_status = netinfo.network_status() current_config = ui.main(CONFIGS, current_config, network_status) try: while True: last_started = datetime.now() config = CONFIGS[current_config] print "Shot: %d Shutter: %s ISO: %d" % (shot, config[0], config[1]) ui.backlight_on() ui.show_status(shot, CONFIGS, current_config) camera.set_shutter_speed(secs=config[0]) camera.set_iso(iso=str(config[1])) ui.backlight_off() filename = camera.capture_image_and_download() prev_acquired = last_acquired brightness = float(idy.mean_brightness(filename)) last_acquired = datetime.now() print "-> %s %s" % (filename, brightness) if brightness < MIN_BRIGHTNESS and current_config < len(CONFIGS) - 1: current_config = current_config + 1 elif brightness > MAX_BRIGHTNESS and current_config > 0: current_config = current_config - 1 else: if last_started and last_acquired and last_acquired - last_started < MIN_INTER_SHOT_DELAY_SECONDS: print "Sleeping for %s" % str(MIN_INTER_SHOT_DELAY_SECONDS - (last_acquired - last_started)) time.sleep((MIN_INTER_SHOT_DELAY_SECONDS - (last_acquired - last_started)).seconds) shot = shot + 1 except Exception,e: ui.show_error(str(e))
class GPhotoTestCase(unittest.TestCase): def setUp(self): self._test_subprocess = FakeSubprocess() self._gphoto = GPhoto(self._test_subprocess) def tearDown(self): pass def test_set_shutter_speed(self): popen = FakePopen('Label: Shutter Speed\nType: MENU\nCurrent: 30\nChoice: 0 Bulb\nChoice: 4 2', '', 0) self._test_subprocess.set_Popen_for_cmd('gphoto2 --get-config /main/settings/shutterspeed', popen) self._gphoto.set_shutter_speed(secs="2") assert ['gphoto2 --get-config /main/settings/shutterspeed'] in self._test_subprocess.get_invocations() assert ['gphoto2 --set-config /main/settings/shutterspeed=4'] in self._test_subprocess.get_invocations() def test_get_camera_time(self): data = ''.join(file('testdata/datetime', 'r').readlines()) popen = FakePopen(data, '', 0) self._test_subprocess.set_Popen_for_cmd('gphoto2 --get-config /main/status/datetime', popen) tim = self._gphoto.get_camera_date_time() assert time.strptime("2013-01-10 07:16:59", "%Y-%m-%d %H:%M:%S") == tim
def main(): # print "Testing Configs" # test_configs() print "Timelapse" camera = GPhoto(subprocess) idy = Identify(subprocess) netinfo = NetworkInfo(subprocess) persist = Persist() #ui = TimelapseUi() initVal = 14 current_config = persist.readLastConfig(initVal) shot = 0 prev_acquired = None last_acquired = None last_started = None network_status = netinfo.network_status() #current_config = 0 #ui.main(CONFIGS, current_config, network_status) try: while True: last_started = datetime.now() config = CONFIGS[current_config] print "Shot: %d Shutter: %s ISO: %d" % (shot, config[1], config[3]) #ui.backlight_on() #ui.show_status(shot, CONFIGS, current_config) camera.set_shutter_speed(secs=config[1]) camera.set_iso(iso=str(config[3])) #ui.backlight_off() try: filename = camera.capture_image_and_download() filenameWithCnt = "IMG_{:0>5d}.jpg".format(shot) os.rename(filename, filenameWithCnt) filename = filenameWithCnt except Exception, e: print "Error on capture." + str(e) print "Retrying..." # Occasionally, capture can fail but retries will be successful. continue prev_acquired = last_acquired brightness = float(idy.mean_brightness(filename)) last_acquired = datetime.now() print "-> %s %s" % (filename, brightness) if brightness < MIN_BRIGHTNESS and current_config < len( CONFIGS) - 1: current_config = current_config + 1 persist.writeLastConfig(current_config) elif brightness > MAX_BRIGHTNESS and current_config > 0: current_config = current_config - 1 persist.writeLastConfig(current_config) else: if last_started and last_acquired and last_acquired - last_started < MIN_INTER_SHOT_DELAY_SECONDS: print "Sleeping for %s" % str( MIN_INTER_SHOT_DELAY_SECONDS - (last_acquired - last_started)) time.sleep((MIN_INTER_SHOT_DELAY_SECONDS - (last_acquired - last_started)).seconds) shot = shot + 1 except Exception, e: #ui.show_error(str(e)) print str(e)
def main(): print "Timelapse starting at %s" % (time.asctime()) camera = GPhoto(subprocess) info = Analyse(subprocess) sysinfo = SystemStats(subprocess) current_config = 19 shot = 0 failures = 0 prev_acquired = None last_acquired = None last_started = None try: while True: last_started = datetime.now() shot = shot + 1 config = CONFIGS[current_config] print "Shot %d : %s" % (shot, time.asctime()) print "Shot %d : Shutter: %ss , ISO: %d , Ap: %s" % ( shot, config[0], config[1], config[2]) sys.stdout.flush() camera.set_shutter_speed(secs=config[0]) camera.set_iso(iso=str(config[1])) camera.set_aperture(ap=config[2]) try: filename = camera.capture_image_and_download() except Exception, e: print "Error on capture: " + str(e) failures += 1 if failures > 2: print "3 successive failures: the camera doesn't work!" sys.stdout.flush() break print "Retrying..." sys.stdout.flush() # Occasionally, capture can fail but retries will be successful. continue failures = 0 #print "Shot %d Filename: %s" % (shot, filename) sys.stdout.flush() prev_acquired = last_acquired brightness = float(info.mean_brightness('webkamera-tmp.jpg')) last_acquired = datetime.now() #health = sysinfo.stats() print "Shot %d : Brightness: %s " % (shot, brightness) sys.stdout.flush() if brightness < TARGET_BRIGHTNESS * 0.9 and current_config < len( CONFIGS) - 1: if TARGET_BRIGHTNESS - brightness > TARGET_BRIGHTNESS * 0.44 and current_config < len( CONFIGS) - 2: current_config += 2 print "Shot %d : EV step: +2/3" % (shot) else: current_config += 1 print "Shot %d : EV step: +1/3" % (shot) elif brightness > TARGET_BRIGHTNESS * 1.1 and current_config > 0: if brightness - TARGET_BRIGHTNESS > TARGET_BRIGHTNESS * 0.44 and current_config > 2: current_config -= 2 print "Shot %d : EV step: -2/3" % (shot) else: current_config -= 1 print "Shot %d : EV step: -1/3" % (shot) else: if last_started and last_acquired and last_acquired - last_started < MIN_INTER_SHOT_DELAY_SECONDS: sleep_for = max((MIN_INTER_SHOT_DELAY_SECONDS - (last_acquired - last_started)).seconds, 0) print "Sleeping for %ss ..." % str(sleep_for) sys.stdout.flush() time.sleep(sleep_for) except Exception, e: print str(e)
def main(): #print "Testing Configs" #test_configs() timestr = str(datetime.now()) print "No problem. Timelapse starts now, at " + timestr camera = GPhoto(subprocess) idy = Identify(subprocess) netinfo = NetworkInfo(subprocess) #ui = TimelapseUi() current_config = 28 shot = 0 prev_acquired = None last_acquired = None last_started = None #network_status = netinfo.network_status() #current_config = ui.main(CONFIGS, current_config, network_status) try: while True: last_started = datetime.now() config = CONFIGS[current_config] print "Shot: %d Shutter: %s ISO: %d" % (shot, config[0], config[1]) #ui.backlight_on() #ui.show_status(shot, CONFIGS, current_config) camera.set_shutter_speed(secs=config[0]) camera.set_iso(iso=str(config[1])) #ui.backlight_off() try: filename = camera.capture_image_and_download(shot) print "Capture signaled." except Exception, e: print "Error on capture." + str(e) print "Retrying..." # Occasionally, capture can fail but retries will be successful. continue prev_acquired = last_acquired brightness = float(idy.mean_brightness(filename)) last_acquired = datetime.now() print "-> %s Brightness: %s" % (filename, brightness) if brightness < MIN_BRIGHTNESS and current_config < len( CONFIGS) - 1: current_config = current_config + 1 print "WARNING: Brightness is below threshold " + strMIN_BRIGHTNESS + ", trying a brighter config NOW!" elif brightness > MAX_BRIGHTNESS and current_config > 0: print "WARNING: Brightness is above threshold " + strMAX_BRIGHTNESS + ", trying a darker config NOW!" else: if last_started and last_acquired and last_acquired - last_started < MIN_INTER_SHOT_DELAY_SECONDS: print "Sleeping for %s" % str( MIN_INTER_SHOT_DELAY_SECONDS - (last_acquired - last_started)) time.sleep((MIN_INTER_SHOT_DELAY_SECONDS - (last_acquired - last_started)).seconds) shot = shot + 1 except Exception, e: #ui.show_error(str(e)) print(str(e))
def main(): print "Timelapse starting at %s" % (time.asctime()) camera = GPhoto(subprocess) info = Analyse(subprocess) sysinfo = SystemStats(subprocess) current_config = 19 shot = 0 failures = 0 prev_acquired = None last_acquired = None last_started = None try: while True: last_started = datetime.now() shot = shot + 1 config = CONFIGS[current_config] print "Shot %d : %s" % (shot, time.asctime()) print "Shot %d : Shutter: %ss , ISO: %d , Ap: %s" % (shot, config[0], config[1], config[2]) sys.stdout.flush() camera.set_shutter_speed(secs=config[0]) camera.set_iso(iso=str(config[1])) camera.set_aperture(ap=config[2]) try: filename = camera.capture_image_and_download() except Exception, e: print "Error on capture: " + str(e) failures += 1 if failures > 2: print "3 successive failures: the camera doesn't work!" sys.stdout.flush() break print "Retrying..." sys.stdout.flush() # Occasionally, capture can fail but retries will be successful. continue failures = 0 # print "Shot %d Filename: %s" % (shot, filename) sys.stdout.flush() prev_acquired = last_acquired brightness = float(info.mean_brightness("webkamera-tmp.jpg")) last_acquired = datetime.now() # health = sysinfo.stats() print "Shot %d : Brightness: %s " % (shot, brightness) sys.stdout.flush() if brightness < TARGET_BRIGHTNESS * 0.9 and current_config < len(CONFIGS) - 1: if TARGET_BRIGHTNESS - brightness > TARGET_BRIGHTNESS * 0.44 and current_config < len(CONFIGS) - 2: current_config += 2 print "Shot %d : EV step: +2/3" % (shot) else: current_config += 1 print "Shot %d : EV step: +1/3" % (shot) elif brightness > TARGET_BRIGHTNESS * 1.1 and current_config > 0: if brightness - TARGET_BRIGHTNESS > TARGET_BRIGHTNESS * 0.44 and current_config > 2: current_config -= 2 print "Shot %d : EV step: -2/3" % (shot) else: current_config -= 1 print "Shot %d : EV step: -1/3" % (shot) else: if last_started and last_acquired and last_acquired - last_started < MIN_INTER_SHOT_DELAY_SECONDS: sleep_for = max((MIN_INTER_SHOT_DELAY_SECONDS - (last_acquired - last_started)).seconds, 0) print "Sleeping for %ss ..." % str(sleep_for) sys.stdout.flush() time.sleep(sleep_for) except Exception, e: print str(e)