cloudprog-hw4/upload.py
2023-04-30 18:43:13 +08:00

19 lines
351 B
Python

import datetime
import cv2
import boto3
BUCKET = ""
FORMAT = "jpg"
cam = cv2.VideoCapture(0)
s3 = boto3.client('s3')
ret, frame = cam.read()
ret, img = cv2.imencode(FORMAT, frame)
response = s3.put_object(
Body=img.tobytes(),
Bucket=BUCKET,
Key=datetime.datetime.strftime(datetime.datetime.now(), "%Y-%m-%d-%H-%M-%S") + "." + FORMAT
)