· 7 years ago · Nov 12, 2018, 07:42 AM
1#!/usr/env/bin python
2# initialize the camera and grab a reference to the raw camera capture
3
4from picamera.array import PiRGBArray
5from picamera import PiCamera
6import time
7import cv2
8import boto3
9from io import BytesIO
10ACCESS_KEY = "AKIAJP6MOMJ2AVTHYPEA"
11SECRET_KEY = "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"
12
13client = boto3.client(
14 's3',
15 aws_access_key_id=ACCESS_KEY,
16 aws_secret_access_key=SECRET_KEY
17)
18
19camera = PiCamera()
20camera.resolution = (1280, 720)
21camera.framerate = 32
22rawCapture = PiRGBArray(camera, size=(1280, 720))
23
24# allow the camera to warmup
25time.sleep(0.1)
26c = 0
27# capture frames from the camera
28for frame in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True):
29 # grab the raw NumPy array representing the image, then initialize the timestamp
30 # and occupied/unoccupied text
31 image = frame.array
32 img_str = cv2.imencode('.jpg', image)[1].tostring()
33 if (c % 10 == 0):
34 io1 = BytesIO()
35 io1.write(img_str)
36 io1.seek(0)
37 print len(io1.getvalue())
38 client.upload_fileobj(io1, "tumeke-images", "testim"+str(c)+".jpg", ExtraArgs={ "ContentType": "image/jpeg"})
39 rawCapture.truncate(0)
40 c+=1