无法将视频的动态图像帧上传到S3

时间:2017-06-03 12:09:23

标签: image python-2.7 amazon-s3

我需要从视频中检测人脸并在S3中存储图像帧

我被困在 s3_client.upload_file 如何添加视频的动态帧

import numpy as np
import boto3
from boto.s3.key import Key
import cv2

count=0
loop=0
cascPath = 'haarcascade_frontalface_default.xml'
faceCascade = cv2.CascadeClassifier(cascPath)
cap = cv2.VideoCapture('https://s3-us-west-2.amazonaws.com/test1/news.mp4')

s3_client = boto3.client('s3')

while(cap.isOpened()):
ret, frame = cap.read()


faces = faceCascade.detectMultiScale(
    frame,
    scaleFactor=2.1,
    minNeighbors=5,
    minSize=(30, 30),
    flags=cv2.CASCADE_SCALE_IMAGE
)
print('------',faces)
#print('------',loop)

for (x, y, w, h) in faces:
        cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)
        crop_img = frame[y:y+h,x:x+w]
        cv2.imwrite('frame%d.jpg' %count, crop_img)
        s3_client.upload_file('frame%d.jpg', 'test1', 'frame%d.jpg' )
        print('---storing in S3----------')
        count += 1
cap.release()
cv2.destroyAllWindows()

0 个答案:

没有答案