forked from sashaDoubov/PiCamDataGathering
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimed_capture.py
More file actions
70 lines (52 loc) · 1.66 KB
/
Copy pathtimed_capture.py
File metadata and controls
70 lines (52 loc) · 1.66 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from picamera import PiCamera
import time
import datetime
import imutils
import pudb
import sys
import os
import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
if len(sys.argv) != 2:
print("Improper cmd-line args, must pass in path to save to!")
sys.exit(0)
homeDir = sys.argv[1]
if not os.path.isdir(homeDir):
print("Not a directory path!")
sys.exit(0)
# camera init
logger.info("Initializing Camera...")
camera = PiCamera()
camera.resolution = (3280, 2464)
# necessary to warm-up
time.sleep(0.1)
logger.info("Done initializing")
lastUploaded = None
numUploaded = 0
now = datetime.datetime.now()
endTime = now.replace(hour=22, minute=0, second=0,microsecond=0)
dayString = now.strftime("%b-%d-%a")
uploadPath = os.path.join(homeDir, dayString)
captureRate = 3*60 # capture period (in sec)
logger.info("Capture every {} seconds".format(captureRate))
logger.info("Creating directory for today")
# safely create today's directory
try:
os.makedirs(uploadPath)
except OSError:
if not os.path.isdir(uploadPath):
raise
logger.info("Entering camera capturing loop...")
while(True):
timestamp = datetime.datetime.now()
if timestamp > endTime:
logger.info("timestamp exceeds 6pm mark, exiting program!")
# stop gathering
sys.exit(0)
if lastUploaded is None or (timestamp - lastUploaded).seconds >= captureRate:
filePath = os.path.join(uploadPath, "cap_{:03d}.jpg".format(numUploaded))
logger.info("Uploading image: {} @ {}".format(filePath, timestamp.strftime("%H:%M")))
camera.capture(filePath)
lastUploaded = timestamp
numUploaded += 1