Exemplo n.º 1
0
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))
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
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)
class IdentifyTestCase(unittest.TestCase):

    def setUp(self):
        self._test_subprocess = FakeSubprocess()
        self._identify = Identify(self._test_subprocess)

    def tearDown(self):
        pass

    def test_brightness(self):
        self._identify.mean_brightness('test.jpg')
        assert 'identify -format "%[mean]" test.jpg' in self._test_subprocess.get_invocations()
Exemplo n.º 5
0
    def __init__(self):
        self.camera = GPhoto(subprocess)
        self.idy = Identify(subprocess)
        self.netinfo = NetworkInfo(subprocess)
        self.shot = 0

        self.displaySet = False
Exemplo n.º 6
0
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))
Exemplo n.º 7
0
def main():
    camera = Raspistill(subprocess)
    idy = Identify(subprocess)

    current_config = 11
    shot = 0
    last_acquired = None
    last_started = None

    try:
        while True:
            last_started = datetime.now()
            config = CONFIGS[current_config]
            print "Shot: %d Shutter: %s ISO: %d" % (shot, config[0], config[1])
            camera.set_shutter_speed(secs=config[0])
            camera.set_iso(iso=config[1])
            # TODO: generalize file output
            filename = "/mnt/output/py/maple-%s.jpg" % time.strftime("%j-%H-%M")
            try:
              camera.capture_image(filename)
            except Exception, e:
              print "Error on capture." + str(e)
              print "Retrying..."
              # Occasionally, capture can fail but retries will be successful.
              continue
            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
                os.unlink(filename)
                continue  # Try again.
            elif brightness > MAX_BRIGHTNESS and current_config > 0:
                current_config = current_config - 1
                os.unlink(filename)
                continue  # Try again.
            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 e
Exemplo n.º 8
0
class IdentifyTestCase(unittest.TestCase):

    def setUp(self):
        self._test_subprocess = FakeSubprocess()
        self._identify = Identify(self._test_subprocess)

    def tearDown(self):
        pass

    def test_identify(self):
        popen = FakePopen('test.jpg JPEG 1728x1152 1728x1152+0+0 8-bit DirectClass 652KB 0.000u 0:00.009', '', 0)
        self._test_subprocess.set_Popen_for_cmd('identify test.jpg', popen)
        assert 'JPEG 1728x1152' in self._identify.summary('test.jpg')
        assert 'identify test.jpg' in self._test_subprocess.get_invocations()

    def test_brightness(self):
        self._identify.mean_brightness('test.jpg')
        assert 'identify -format "%[mean]" test.jpg' in self._test_subprocess.get_invocations()
Exemplo n.º 9
0
class IdentifyTestCase(unittest.TestCase):
    def setUp(self):
        self._test_subprocess = FakeSubprocess()
        self._identify = Identify(self._test_subprocess)

    def tearDown(self):
        pass

    def test_identify(self):
        popen = FakePopen(
            'test.jpg JPEG 1728x1152 1728x1152+0+0 8-bit DirectClass 652KB 0.000u 0:00.009',
            '', 0)
        self._test_subprocess.set_Popen_for_cmd('identify test.jpg', popen)
        assert 'JPEG 1728x1152' in self._identify.summary('test.jpg')
        assert 'identify test.jpg' in self._test_subprocess.get_invocations()

    def test_brightness(self):
        self._identify.mean_brightness('test.jpg')
        assert 'identify -format "%[mean]" test.jpg' in self._test_subprocess.get_invocations(
        )
Exemplo n.º 10
0
 def __init__(self):
     self.LCDAttached = self.checkPanel()
     # Initialize the LCD using the pins
     # see https://learn.adafruit.com/adafruit-16x2-character-lcd-plus-keypad-for-raspberry-pi/usage
     if (self.LCDAttached == True):
       Adafruit_CharLCDPlate.__init__(self)
     self.camera = GPhoto(subprocess)
     self.idy = Identify(subprocess)
     self.netinfo = NetworkInfo(subprocess)
     self.shot = 0
     
     self.displaySet = False
Exemplo n.º 11
0
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)
Exemplo n.º 12
0
def main():
    client = mqtt.Client()
    client.on_connect = on_connect
    client.connect("192.168.178.101", 1883, 60)
    client.loop_start()

    teststart=float(time.time()) # Startzeit abspeichern und am Ende mit der Endzeit anzeigen
    idy = Identify(subprocess) # das ist ImageMagick
    if verbosemode==True:
        logging.basicConfig(level=logging.DEBUG)
    print "#######################"
    print "# KH Pi Cam Timelapse #"
    print "#######################"
    print "\nAufnahmedauer: %d Minuten" % capturelength
    print "Anzahl Aufnahmen: %d" % totalshots
    print "Pause zwischen den Fotos: %d Sekunden" % intershotdelay

    current_config = int((len(CONFIGS)-1)/2) # in der Mitte der Einstellungen starten
    width = 1296
    height = 730
    shot = 0
    prev_acquired = None
    last_acquired = None
    last_started = None
    comment="Start"
    
# Unterordner für die Bilder der Serie mit datetime.now() erstellen
    timestr = time.strftime("%Y%m%d-%H%M%S")
    os.mkdir(timestr, 0755 )
    
    try:
        #das erste Mal außerhalb der Schleife, später schon nach dem Sleep damit Änderungen der Belichtung mit gestoppt werden
        starttime = float(time.time())
        while shot < totalshots:
            #last_started = datetime.now()
            config = CONFIGS[current_config]
            filename = timestr + '/image%05d.jpg' % shot
            client.publish("zigbee2mqtt/Lampe_Schreibtisch/set", "{   \"state\": \"ON\", \"transition\": \"2\" }")
            time.sleep(2)
            if useraspistill == False:
                with picamera.PiCamera() as camera:
                    camera.exif_tags['IFD0.Artist'] = 'Karsten Hartlieb'
                    camera.exif_tags['IFD0.Copyright'] = 'Copyright (c) 2015 Karsten Hartlieb'
                    camera.resolution = (width, height)
                    camera.exposure_mode = 'off'
                    camera.shutter_speed = config[2]
                    camera.iso = config[0]
                    camera.start_preview()
                    # Give the camera some time to adjust to conditions
                    time.sleep(2)
                    camera.capture(filename)
                    camera.stop_preview()
                    time.sleep(2)
            else:
                optionstring = "-w %d -h %d -t 1 -ISO %d --shutter %d -o %s" % (width, height, config[0], config[2], filename)
                if verbosemode == True:
                    optionstring = "-w %d -h %d -v -t 1 -ISO %d --shutter %d -o %s" % (width, height, config[0], config[2], filename)
                    print optionstring
                os.system("raspistill " + optionstring)

            time.sleep(2)    
            client.publish("zigbee2mqtt/Lampe_Schreibtisch/set", "{   \"state\": \"OFF\", \"transition\": \"2\" }")

            #prev_acquired = last_acquired
            brightness = float(idy.mean_brightness(filename))
            #last_acquired = datetime.now()
            
            if shot%20 == 0:
                # alle paar Zeilen die Überschrift widerholen
                print "\nBildNr.| Shutter  | ISO | Helligkeit | Kommentar"
                print "------------------------------------------------------------"
            #print " %05d |      %.2f sek   | %d |    %s  | %s" % (shot, float(config[0])/1000000, config[1], brightness, comment)
            print " %05d | %s | %d |      %5.0f | %s" % (shot, config[1], config[0], brightness, comment)

            if brightness < MIN_BRIGHTNESS and current_config < len(CONFIGS) - 1:
                current_config = current_config + 1
                comment = "Belichtungskorrektur"
                if verbosemode == True:
                    print "Mittlere Helligkeit=%0.2f, erhöhe Belichtungszeit/ISO" %brightness
            elif brightness > MAX_BRIGHTNESS and current_config > 0:
                current_config = current_config - 1
                comment = "Belichtungskorrektur"
                if verbosemode == True:
                    print "Mittlere Helligkeit=%0.2f, erhöhe Belichtungszeit/ISO" %brightness
            else:
                comment=""
                endtime = float(time.time()) #datetime.now()
                #print "Dauer der Auslösung: %f" % (endtime-starttime)
                #if ((endtime - starttime) > timedelta(seconds=int(intershotdelay))):
                #if (int((endtime - starttime).strftime("%S")) > intershotdelay):
                if ((int(endtime) - int(starttime)) < intershotdelay):
                    #print "bis hier gehts noch"
                    #time.sleep((intershotdelay - (endtime - starttime)).seconds)
                    time.sleep(intershotdelay - (endtime - starttime))
                else:
                    comment="Zeitüberschreitung"
                #if last_started and last_acquired and last_acquired - last_started < intershotdelay:
                    #if verbosemode==True:
                        #print "Sleeping for %s" % str(intershotdelay - (last_acquired - last_started))
                    
                    #time.sleep((intershotdelay - (last_acquired - last_started)).seconds)
                    
            starttime = float(time.time())
            shot = shot + 1
            
            # Wenn gewünscht, jedes Bild nach dem Schießen auf dem TFT anzeigen aber Konsolen-Ausgabe unterdrücken
            if displaycapturedimages == True:
                # hier wird jedesmal ein neuer Prozess gestartet, wie kann man das verhindern?
                os.system("fbi -a -T 1 " +filename + " 2> /dev/null")

    except Exception,e:
        print str(e)
Exemplo n.º 13
0
def main():
    teststart=float(time.time()) # Startzeit abspeichern und am Ende mit der Endzeit anzeigen
    idy = Identify(subprocess) # das ist ImageMagick
    if verbosemode==True:
        logging.basicConfig(level=logging.DEBUG)
    print "#######################"
    print "# KH Pi Cam Timelapse #"
    print "#######################"
    print "\nAufnahmedauer: %d Minuten" % capturelength
    print "Anzahl Aufnahmen: %d" % totalshots
    print "Pause zwischen den Fotos: %d Sekunden" % intershotdelay

    current_config = int((len(CONFIGS)-1)/2) # in der Mitte der Einstellungen starten
    width = 1296
    height = 730
    shot = 0
    prev_acquired = None
    last_acquired = None
    last_started = None
    comment="Start"
    
# Unterordner für die Bilder der Serie mit datetime.now() erstellen
    timestr = time.strftime("%Y%m%d-%H%M%S")
    os.mkdir(timestr, 0755 )
    
    try:
        #das erste Mal außerhalb der Schleife, später schon nach dem Sleep damit Änderungen der Belichtung mit gestoppt werden
        starttime = float(time.time())
        while shot < totalshots:
            #last_started = datetime.now()
            config = CONFIGS[current_config]
            filename = timestr + '/image%05d.jpg' % shot
            if useraspistill == False:
                with picamera.PiCamera() as camera:
                    camera.exif_tags['IFD0.Artist'] = 'Karsten Hartlieb'
                    camera.exif_tags['IFD0.Copyright'] = 'Copyright (c) 2015 Karsten Hartlieb'
                    camera.resolution = (width, height)
                    camera.exposure_mode = 'off'
                    camera.shutter_speed = config[2]
                    camera.iso = config[0]
                    camera.start_preview()
                    # Give the camera some time to adjust to conditions
                    time.sleep(2)
                    camera.capture(filename)
                    camera.stop_preview()
            else:
                optionstring = "-w %d -h %d -t 1 -ISO %d --shutter %d -o %s" % (width, height, config[0], config[2], filename)
                if verbosemode == True:
                    optionstring = "-w %d -h %d -v -t 1 -ISO %d --shutter %d -o %s" % (width, height, config[0], config[2], filename)
                    print optionstring
                os.system("raspistill " + optionstring)
                

            #prev_acquired = last_acquired
            brightness = float(idy.mean_brightness(filename))
            #last_acquired = datetime.now()
            
            if shot%20 == 0:
                # alle paar Zeilen die Überschrift widerholen
                print "\nBildNr.| Shutter  | ISO | Helligkeit | Kommentar"
                print "------------------------------------------------------------"
            #print " %05d |      %.2f sek   | %d |    %s  | %s" % (shot, float(config[0])/1000000, config[1], brightness, comment)
            print " %05d | %s | %d |      %5.0f | %s" % (shot, config[1], config[0], brightness, comment)

            if brightness < MIN_BRIGHTNESS and current_config < len(CONFIGS) - 1:
                current_config = current_config + 1
                comment = "Belichtungskorrektur"
                if verbosemode == True:
                    print "Mittlere Helligkeit=%0.2f, erhöhe Belichtungszeit/ISO" %brightness
            elif brightness > MAX_BRIGHTNESS and current_config > 0:
                current_config = current_config - 1
                comment = "Belichtungskorrektur"
                if verbosemode == True:
                    print "Mittlere Helligkeit=%0.2f, erhöhe Belichtungszeit/ISO" %brightness
            else:
                comment=""
                endtime = float(time.time()) #datetime.now()
                #print "Dauer der Auslösung: %f" % (endtime-starttime)
                #if ((endtime - starttime) > timedelta(seconds=int(intershotdelay))):
                #if (int((endtime - starttime).strftime("%S")) > intershotdelay):
                if ((int(endtime) - int(starttime)) < intershotdelay):
                    #print "bis hier gehts noch"
                    #time.sleep((intershotdelay - (endtime - starttime)).seconds)
                    time.sleep(intershotdelay - (endtime - starttime))
                else:
                    comment="Zeitüberschreitung"
                #if last_started and last_acquired and last_acquired - last_started < intershotdelay:
                    #if verbosemode==True:
                        #print "Sleeping for %s" % str(intershotdelay - (last_acquired - last_started))
                    
                    #time.sleep((intershotdelay - (last_acquired - last_started)).seconds)
                    
            starttime = float(time.time())
            shot = shot + 1
            
            # Wenn gewünscht, jedes Bild nach dem Schießen auf dem TFT anzeigen aber Konsolen-Ausgabe unterdrücken
            if displaycapturedimages == True:
                # hier wird jedesmal ein neuer Prozess gestartet, wie kann man das verhindern?
                os.system("fbi -a -T 1 " +filename + " 2> /dev/null")

    except Exception,e:
        print str(e)
Exemplo n.º 14
0
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))
Exemplo n.º 15
0
 def setUp(self):
     self._test_subprocess = FakeSubprocess()
     self._identify = Identify(self._test_subprocess)
Exemplo n.º 16
0
 def setUp(self):
     self._test_subprocess = FakeSubprocess()
     self._identify = Identify(self._test_subprocess)