gpt4 book ai didi

python - 将多个帧发送到 AWS rekognition

转载 作者:太空宇宙 更新时间:2023-11-03 21:50:40 25 4
gpt4 key购买 nike

我正在尝试从我的网络摄像头向 aws rekognition 发送图片,以使用 python 检测坐在它前面的人的事件。

为此,我每 5 秒拍一张照片并将其发送到 aws。但是当我这样做时,他似乎总是发回有关我发送的第一帧的信息

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)

这是我从那个电话中得到的结果:

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

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

最佳答案

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

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 不需要全尺寸来检测人脸。

关于python - 将多个帧发送到 AWS rekognition,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50741636/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com