-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcaptureimages.py
More file actions
55 lines (49 loc) · 1.52 KB
/
captureimages.py
File metadata and controls
55 lines (49 loc) · 1.52 KB
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
import sys
import time
import picamera
import RPi.GPIO as GPIO
savelocation= ""
#variable used for a count of the number of photos taken
piccount = 0
#variable for the time to sleep after taking a photo in seconds
sleepaftertaking = 2
#variable to set the number of photos to take - count from zero
photostotake = 65;
# function to take picture
def takepic(channel=0):
#t = time.time()
#t = count
global piccount
global savelocation
count = piccount
piccount = piccount + 1
with picamera.PiCamera() as camera:
camera.resolution = (2592,1944)
camera.start_preview()
time.sleep(1)
camera.capture(savelocation + str(time.strftime("%Y%m%d_%H%M%S")) + str(count) + '.jpg')
time.sleep(sleepaftertaking)
# main function of program
def main(argv):
role = argv[0]
pin = int(argv[3])
GPIO.setmode(GPIO.BOARD)
if role == "master":
GPIO.setup(pin, GPIO.OUT)
GPIO.output(pin, GPIO.LOW)
while (piccount <= photostotake):
GPIO.output(pin, GPIO.HIGH)
takepic()
GPIO.output(pin, GPIO.LOW)
time.sleep(5)
else:
GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.add_event_detect(pin, GPIO.RISING)
GPIO.add_event_callback(pin,takepic)
while (piccount <= (photostotake-1)):
time.sleep(0.01)
GPIO.cleanup()
if __name__=="__main__":
savelocation = "/mnt/" + str(sys.argv[3]) + "-" + str(sys.argv[2]) + "-"
piccount = 0
main(sys.argv[1:])