This repository has been archived by the owner on Jan 14, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
camera.py
70 lines (59 loc) · 1.55 KB
/
camera.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
import picamera
from time import sleep, gmtime
import os.path
FOLDER_PATH = '/var/lib/crtlvc/media'
#
# Duration of video capture, in seconds
#
VIDEO_DURATION = 600
#
# Returns the current time as a string with the format:
# mm-dd@hh:mm:ss
#
def getCurrentTimeString ():
tm = gmtime()
return "%04d-%02d-%02d_%02d-%02d-%02d" % \
(tm.tm_year,tm.tm_mon,tm.tm_mday,tm.tm_hour,
tm.tm_min,tm.tm_sec)
try:
#
# Initialize camera and settings
#
camera = picamera.PiCamera()
camera.sharpness = 0
camera.contrast = 0
camera.brightness = 50
camera.saturation = 0
camera.ISO = 0
camera.video_stabilization = False
camera.exposure_compensation = 0
camera.exposure_mode = 'auto'
camera.meter_mode = 'average'
camera.awb_mode = 'auto'
camera.image_effect = 'none'
camera.color_effects = None
camera.rotation = 0
camera.hflip = False
camera.vflip = False
camera.crop = (0.0, 0.0, 1.0, 1.0)
#
# Take initial image
#
camera.capture(os.path.join(FOLDER_PATH,'init_image_' + getCurrentTimeString() + '.jpg'))
#
# Capture video
#
camera.start_recording(os.path.join(FOLDER_PATH,'video_' + getCurrentTimeString() + '.h264'))
#
# Wait predetermined amount of time
#
sleep(VIDEO_DURATION)
finally: #finally clause to stop recording if interrupted during sleep
#
# Stop video capture
#
camera.stop_recording()
#
# Take final image
#
camera.capture(os.path.join(FOLDER_PATH,'fin_image_' + getCurrentTimeString() + '.jpg'))