def renameFiles(i): oled.display0('renaming files') image_location = i print "image_location " + image_location # global resize_location os.chdir(image_location) # go to where the images are lst = os.listdir(".") lst.sort() print lst a = 1 # the counter for images for i in lst: # for each file in the dir if i[-4:] == ".JPG": picCount = "%03d" % a # make the counter 3 decimal places and integrate newName = picCount + ".jpg" a += 1 newName = newName.replace(":", ".") newName = newName.replace(" ", "_") os.rename(i, newName) print "Renamed %r to %r" % (i, newName) # oldLoc = image_location + "/" + newName # newLoc = rename_location + "/" + newName oled.display1(newName) oled.clear()
def makeGif(a, b): oled.display0("making Gif") imageLocation = a shot_date = b imagesToUse = imageLocation + "/" + "%03d" + ".jpg" saveLocation = imageLocation[:-8] # get out of the resize folder gifName = saveLocation + "/" + shot_date + '.gif' subprocess.call([ "ffmpeg", "-framerate", "10", "-i", imagesToUse, "-vf", "scale=iw/2:-1", gifName ]) oled.clear()
def makeVid(a, b): oled.display0("making Vid") imageLocation = a shot_date = b saveLocation = imageLocation[:-8] # get out of the ogs folder print saveLocation movName = saveLocation + "/" + shot_date + '.mp4' print "movName = %r" % movName imagesToUse = imageLocation + "/" + "%03d" + ".jpg" subprocess.call(["ffmpeg", "-f", "image2", "-r", "30", "-i", imagesToUse, \ "-vcodec", "h264", "-y", movName]) oled.clear() return (movName)
def resizeImages(a, b): # going to resize images from a, save to b oled.display0("resizing images") print "resizeImages()" image_location = a resize_location = b os.chdir(image_location) lst = os.listdir(".") lst.sort() lstLen = len(lst) print lst for i in lst: oled.display1(str(i)) # print "gonna resize it" img = Image.open(i) img = img.crop( (603, 600, 603 + 4058, 600 + 2706)) # this is the new line! imgResized = img.resize((1080, 720)) resizedName = resize_location + "/" + i print "resizing " + resizedName[-7:] + " / " + str(lstLen) imgResized.save(resizedName, "JPEG", optimize=True) oled.clear()
def takePictures(n, d): shotDelay = d print "finna take %r pics" % n oled.display0("taking picture") totalWait = 0 adjustedDelay = shotDelay + 0.0 print "ADJUSTED DELAY = " + str(adjustedDelay) for i in range(0, n): shotStart = datetime.now() oled.display1(" " + str(i + 1) + "/" + str(n)) print "photo " + str(i) # sleep(shotDelay) # initialize variable if i > 0: t = datetime.now() # this does the timing instead of sleep while (t - shotEnd).seconds < adjustedDelay: # previously shotDelay # print (t - shotEnd) t = datetime.now() interval = shotEnd - lastShotStart intinterval = interval.seconds + round( float(interval.microseconds) / 1000000, 3) print "interval = " + str(intinterval) totalWait += intinterval averageInterval = totalWait / i print "averageInterval = " + str(averageInterval) averageDifference = averageInterval - shotDelay adjustedDelay = shotDelay - averageDifference print "averageDifference = " + str(averageDifference) print "ADJUSTED DELAY = " + str(adjustedDelay) shot_time = takePicture() print "shot_time = " + str(shot_time) lastShotStart = shotStart shotEnd = datetime.now() oled.clear()
def downloadImages(): oled.display0("downloading images") print "downloading" gp(downloadCommand) gp(clearCommand) oled.clear()
def targetTime( a, b ): # a will be time in advance of the event to start shooting. b 1 for sunrise, 2 for sunset ''' this function gets the time of sunrise/set, subtracts the lead up time to calculate the target time, then waits until that time. a is the time ahead of sunrise/set set b to 1 for sunrise, 2 for sunset ''' oled.clear() oled.display0("GETTING START TIME") if b == 1: oled.display1("getting SUNRISE") print "calculating the time %r minutes before SUNRISE" % a zeroTime = getSunriseTime( ) # zero time is the time of the event, either sunset or rise oled.display1("sunrise:" + zeroTime) msgL2 = "sunrise was at " + str(zeroTime) elif b == 2: oled.display1("getting SUNSET") print "calculating the time %r minutes before SUNSET" % a zeroTime = getSunsetTime() oled.display1("sunset:" + zeroTime) msgL2 = "sunset was at " + str(zeroTime) elif b == 3: oled.display1("going in 1") print "waiting for next minute" d = datetime.datetime.now() + datetime.timedelta(minutes=1) d = d.strftime("%H:%M") zeroTime = str(d) a = 1 # set offset to 1 msgL2 = "started manually" else: print """error, b needs to either be 1 for sunrise or 2 for sunset or 3 for test for all day enter 4""" oled.display0("ERROR") zeroHour = int(zeroTime[0:2]) zeroMin = int(zeroTime[3:5]) zeroDelta = datetime.timedelta(hours=zeroHour, minutes=zeroMin) now = datetime.datetime.now() nowDelta = datetime.timedelta(minutes=now.minute, hours=now.hour) # print "nowDelta", nowDelta # print "now" , now offset = datetime.timedelta(minutes=a) # print "offset", offset targetTime = zeroDelta - offset wait(targetTime) # following commmented out section was replaced by wait() # print "targetTime", targetTime # secondsTillTarget = (targetTime - nowDelta).seconds # # print "secondsTillTarget", secondsTillTarget # hoursTillTarget = secondsTillTarget // 3600 # targetHour = targetTime.seconds // 3600 # targetMin = ((targetTime.seconds)//60)%60 # oled.display0("starting at " + str(targetHour) + ":" + str(targetMin)) # print "waiting for the %rth hour" % targetHour # while now.hour != targetHour: # # print "waiting for the right hour" # now = datetime.datetime.now() # nowHour = now.hour # nowMin = now.minute # oled.display1("now it's " + str(nowHour) + ":" + str(nowMin)) # sleep(60) # print "hour matched!" # print "waiting for the %rth minute" % targetMin # prevNow = now # while now.minute != targetMin: # now = datetime.datetime.now() # nowHour = now.hour # nowMin = now.minute # if prevNow != now: # oled.display1("now it's " + str(nowHour) + ":" + str(nowMin)) # if now.minute == targetMin: # oled.display1("bout to start") # sleep(15) # prevNow = now print "it is time" msgL1 = "started shooting at " + str(targetTime) return msgL1 + "\n" + msgL2