将多个帧发送到AWS识别 [英] Send multiple frame to AWS rekognition

查看:107
本文介绍了将多个帧发送到AWS识别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过网络摄像头向aw认可发送图片,以使用python检测坐在它前面的人的活动.

I'm trying to send pictures to the aws rekognition from my webcam to detect the activity of the person sitting in front of it using python.

为此,我每5秒钟拍摄一张照片,然后将其发送给aws. 但是当我这样做时,似乎他一直在回发有关我发送的第一帧的信息

To do so I take a picture every 5 seconds and I send it to the aws. But when I do so it seems that he's always sending back information about the first frame that I sent

cap = cv2.VideoCapture(0)

while 1:
   ret, img = cap.read()
   client=boto3.client('rekognition')

   print("hello")
   ret, fileImg=cv2.imencode('.png',img)
   response = client.detect_labels(Image={'Bytes':fileImg.tobytes()})
   print('Detected labels for Camera Capture')    
   for label in response['Labels']:
       print (label['Name'] + ' : ' + str(label['Confidence']))

   sleep(5)

这是我从该通话中得到的结果:

Here is the result i get from that call:

Detected labels for Camera Capture
Human : 99.1103897095
People : 99.1103744507
Person : 99.1103897095
Face : 56.5527687073
Crypt : 51.1719360352
hello
Detected labels for Camera Capture
Human : 99.0247421265
People : 99.0247344971
Person : 99.0247421265
Face : 57.7796173096
Lighting : 51.8473701477
Crypt : 51.08152771
hello
Detected labels for Camera Capture
Human : 99.0808181763
People : 99.0808105469
Person : 99.0808181763
Face : 56.4268836975
Lighting : 54.6302490234
Crypt : 50.8622779846
hello

在通话期间知道图像已发生很大变化,并且(至少我认为)应该向我显示其他结果.

Knowing during the time of the call the image has changed a lot and should (at least I think) show me other results.

推荐答案

以下是一些我用类似的方式在脸部周围放置矩形的代码:

Here's some code that I use to put rectangles around faces in a similar way:

import cv2
import numpy as np
import boto3

# Setup
scale_factor = .15
green = (0,255,0)
red = (0,0,255)
frame_thickness = 2
cap = cv2.VideoCapture(0)
rekognition = boto3.client('rekognition')

while(True):

    # Capture frame-by-frame
    ret, frame = cap.read()
    height, width, channels = frame.shape

    # Convert frame to jpg
    small = cv2.resize(frame, (int(width * scale_factor), int(height * scale_factor)))
    ret, buf = cv2.imencode('.jpg', small)

    # Detect faces in jpg
    faces = rekognition.detect_faces(Image={'Bytes':buf.tobytes()}, Attributes=['ALL'])

    # Draw rectangle around faces
    for face in faces['FaceDetails']:
        smile = face['Smile']['Value']
        cv2.rectangle(frame,
                      (int(face['BoundingBox']['Left']*width),
                       int(face['BoundingBox']['Top']*height)),
                      (int((face['BoundingBox']['Left']+face['BoundingBox']['Width'])*width),
                       int((face['BoundingBox']['Top']+face['BoundingBox']['Height'])*height)),
                      green if smile else red, frame_thickness)

    # Display the resulting frame
    cv2.imshow('frame', frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()

它会按比例缩小图片,因为Rekognition不需要全尺寸来检测脸部.

It scales-down the picture because Rekognition doesn't need full size to detect faces.

这篇关于将多个帧发送到AWS识别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆