Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 向AWS rekognition发送多帧_Python_Amazon Web Services_Opencv_Webcam_Amazon Rekognition - Fatal编程技术网

Python 向AWS rekognition发送多帧

Python 向AWS rekognition发送多帧,python,amazon-web-services,opencv,webcam,amazon-rekognition,Python,Amazon Web Services,Opencv,Webcam,Amazon Rekognition,我正试图从我的网络摄像头向aws rekognition发送图片,以便使用python检测坐在它前面的人的活动 为此,我每5秒拍一张照片,并将其发送给aws。 但当我这么做的时候,他似乎总是把我发送的第一帧的信息发回 cap = cv2.VideoCapture(0) while 1: ret, img = cap.read() client=boto3.client('rekognition') print("hello") ret, fileImg=cv2.ime

我正试图从我的网络摄像头向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()

它缩小了图片的比例,因为Rekognion不需要全尺寸来检测人脸。

您好,谢谢您的回答,我试图调整图像大小,但问题没有解决,我的OpenCv版本似乎总是通过函数cv2.imencode返回相同的jpg图像。我必须将APi调用放在另一个线程中才能正常工作