-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdropboximage.py
52 lines (45 loc) · 1.57 KB
/
dropboximage.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
import picamera
import json
import time
import glob
import os
import dropbox as dbx
from picamera.array import PiRGBArray
import datetime
import warnings
import imutils
import cv2
from pyimagesearch.tempimage import TempImage
def dbxmain():
# Put your token here:
with open("/home/pi/Desktop/pisecuritysystem/permissions.json") as f:
data = json.load(f)
client = dbx.Dropbox(data['db-token'])
# initialize the camera and grab a reference to the raw camera capture
camera = picamera.PiCamera()
#default 640x480 - decrease to go faster
#motion-detect camera resolution
camera.resolution = (1808,1008)
rawCapture = PiRGBArray(camera, size=(1808,1008))
for f in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True):
frame = f.array
timestamp = datetime.datetime.now()
frame = imutils.resize(frame, width=1808)
# draw the text and timestamp on the frame
ts = timestamp.strftime("%A_%d_%m_%Y_%I:%M:%S%p")
cv2.putText(frame, "{}".format(ts), (10, 20),
cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 2)
t = TempImage()
cv2.imwrite(t.path, frame)
print("[UPLOAD] {}".format(ts))
name = "{base}{timestamp}".format(base="", timestamp=ts)
os.rename(t.path[3:], "{new}.jpg".format(new=name))
with open("/home/pi/Desktop/pisecuritysystem/{name}.jpg".format(name=name), "rb") as f:
client.files_upload(f.read(), "/{name}.jpg".format(name=name), mute = True)
os.remove("{name}.jpg".format(name=name))
rawCapture.truncate(0)
break
camera.close()
time.sleep(.5)
if __name__ == '__main__':
dbxmain()