-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcookieCamera.py
93 lines (72 loc) · 3.05 KB
/
cookieCamera.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
import picamera
from picamera import Color
from subprocess import call
from subprocess import Popen
from datetime import datetime
from time import sleep
import threading
def takePics(picTotal):
#our file path
filePath = "/home/pi/Desktop/cookie/Image/"
#picTotal = 1
picCount = 0
while picCount < picTotal:
# grab the current time
currentTime = datetime.now()
#Setup the camera such that it closes
#when we are done with it.
print("About to take a picture.")
print("Add timestamp to pic")
timestampMessage = currentTime.strftime("%Y.%m.%d - %H:%M:%S")
with picamera.PiCamera() as camera:
camera.resolution = (1280,720)
camera.start_preview()
camera.annotate_foreground = Color('black')
camera.annotate_background = Color('white')
camera.annotate_text = timestampMessage
while(datetime.now()-currentTime).seconds <= 5:
camera.annotate_text = datetime.now().strftime("%Y.%m.%d - %H:%M:%S")
sleep(0.2)
# Create file name for our picture
picTime = datetime.now().strftime("%Y.%m.%d-%H%M%S")
picName = picTime + '.jpg'
completeFilePath = filePath + picName
camera.capture(completeFilePath)
camera.stop_preview()
print("Picture taken.")
timestampCommand = "/usr/bin/convert " + completeFilePath + " -pointsize 36 -fill red -annotate +700+650 '" + timestampMessage + "' " + completeFilePath
#Execute our command
#call([timestampCommand], shell=True)
print("timestamp added")
#Advance our picture counter
picCount += 1
sleep(0.5)
def takevid():
# grab the current time
currentTime = datetime.now()
timestampMessage = currentTime.strftime("%Y.%m.%d - %H:%M:%S")
#our file path
filePath = "/home/pi/Desktop/cookie/Video/"
# Create file name for our picture
vidTime = currentTime.strftime("%Y.%m.%d-%H%M%S")
vidName = vidTime + '.h264'
completeFilePath = filePath + vidName
#Setup the camera
with picamera.PiCamera() as camera:
camera.resolution = (1280,720)
camera.start_preview()
camera.annotate_foreground = Color('black')
camera.annotate_background = Color('white')
camera.annotate_text = timestampMessage
camera.start_recording(completeFilePath)
while(datetime.now()-currentTime).seconds <= 10:
camera.annotate_text = datetime.now().strftime("%Y.%m.%d - %H:%M:%S")
camera.wait_recording(0.2)
camera.stop_recording()
camera.stop_preview()
print("convert the video..")
#Define the command we want to execute.
command = "MP4Box -add " + completeFilePath + " " + filePath + vidTime + ".mp4"
#Execute our command
call([command], shell = True)
print("Video converted.")