-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimelapseImageFinal.py
100 lines (74 loc) · 3.44 KB
/
timelapseImageFinal.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
from picamera import PiCamera
import os
from os import system
import datetime
from time import sleep
#######################################################################
# TIMELAPSE PARAMETERS
timeMinutes = 360 #set this to the number of minutes you wish to run your timelapse camera
secondsInterval = 2 #number of seconds delay between each photo taken
#fps = 30 #frames per second timelapse video
numPhotos = int((timeMinutes*60)/secondsInterval) #number of photos to take
#######################################################################
runProgram = input("Run timelapse program? (Y/N): ")
if runProgram.lower() == "n":
print("No selected, Program terminating...")
sleep(2)
quit
elif runProgram.lower() =="y":
#print ("test running sucessful")
print("10 second delay for reading - terminate anytime with [ CTRL + C ]")
print("")
print("--------------------------------")
print("Welcome to the Timelapse code")
print("--------------------------------")
print("")
print("Remember to set timelapse parameters in the file")
print("")
print("AFTER the camera preview begins, press ENTER to end preview and continue the script")
sleep(10)
camera = PiCamera()
camera.start_preview()
#empty true statements
y = 1;
z = 0
negative = "-"
while True:
x = input("Press ENTER to continue")
if x == "":
x = 0.5
break
else:
x = 0.5
break
sleep(x)
camera.stop_preview()
camera.close()
#time to cancel the command before it generates files
print("")
print("Timelapse script is starting... [ Ctrl + C = Terminate at any time]")
sleep(10)
print("")
print("number of photos to take = ", numPhotos)
print("")
dateRaw= datetime.datetime.now()
startDateTimeFormat = dateRaw.strftime("%Y-%m-%d_%H:%M:%S")
os.mkdir('/home/timelapse1/Pictures/' + startDateTimeFormat)
print("The Pi has now started taking photos for your timelapse, start time: " + startDateTimeFormat)
camera = PiCamera()
camera.resolution = (3000, 2000)
for i in range(numPhotos):
camera.capture('/home/timelapse1/Pictures/' + startDateTimeFormat +'/{0:06d}.jpg'.format(i))
sleep(secondsInterval)
dateRaw= datetime.datetime.now()
endDateTimeFormat = dateRaw.strftime("%Y-%m-%d_%H:%M")
print("Photos finished on " + endDateTimeFormat + ". Files located at /home/timelapse1/Pictures/" + startDateTimeFormat)
camera.close()
#print("Please standby as your timelapse video is created.")
#system('ffmpeg -r {} -f image2 -pattern_type glob -i "/home/timelapse1/Pictures/*.jpg" -vcodec mpeg4 -b:v 800k /home/timelapse1/Videos/{}.avi'.format(fps, datetimeformat))
#system('rm /home/timelapse1/Pictures/*.jpg')
#print('Timelapse video is complete. Video saved as /home/timelapse1/Videos/{}.avi'.format(datetimeformat))
#print('Timelapse photo taking is complete. Saved to /home/timelapse1/photos/{}.jpg'.format(datetimeformat))
else:
print("Unknown input, please try again")
quit