amazon-web-services - 使用 AWS Rekognition 从视频中提取人脸

标签 amazon-web-services aws-cli amazon-rekognition

使用 AWS Rekognition,我能够使用以下 nodejs 在 mp4 视频中检测到人脸,

var AWS = require("aws-sdk");                                                                                              
AWS.config.update({                                                                                                        
  region: "us-east-1"                                                                                                      
});                                                                                                                        

var rekognition = new AWS.Rekognition();                                                                                   



var params = {                                                                                                             
  Video: { /* required */                                                                                                  
    S3Object: {                                                                                                            
      Bucket: 'videobucket',                                                                                          
      Name: 'testvideo.mp4'                                                                                                
    }                                                                                                                      
  },                                                                                                                       
  FaceAttributes: "ALL",                                                                                                   
  NotificationChannel: {                                                                                                   
    RoleArn: 'arn:aws:iam::xxx:role/xxx', /* required */                                                     
    SNSTopicArn: 'arn:aws:sns:us-east-1:xxx:alerts' /* required */                                                
  }                                                                                                                        
};                                                                                                                         
rekognition.startFaceDetection(params, function(err, data) {                                                               
  if (err) console.log(err, err.stack); // an error occurred                                                               
  else     console.log(data);           // successful response                                                             
});    

并且能够使用以下 cli 获得结果,

aws rekognition get-face-detection --job-id xxxxxxx



并以以下 json 格式输出人脸,
{                                                                                                                          
    "Faces": [                                                                                                             
        {                                                                                                                  
            "Timestamp": 0,                                                                                                
            "Face": {                                                                                                      
                "BoundingBox": {                                                                                           
                    "Width": 0.029999999329447746,                                                                         
                    "Top": 0.2588889002799988,                                                                             
                    "Left": 0.29374998807907104,                                                                           
                    "Height": 0.052222222089767456                                                                         
                },                                                                                                         
                "Landmarks": [                                                                                             
                    {                                                                                                      
                        "Y": 0.28277161717414856,                                                                          
                        "X": 0.3052537739276886,                                                                           
                        "Type": "eyeLeft"                                                                                  
                    },                                                                                                     
                    {                                                                                                      
                        "Y": 0.27957838773727417,                                                                          
                        "X": 0.3085327744483948,                                                                           
                        "Type": "eyeRight"    

如何将这些人脸提取为图像并将它们转储到 s3 存储桶中?

谢谢

最佳答案

对于您的问题,您可以通过使用从 aws rekognition 返回的边界框从原始图像中裁剪人脸部分来单独获取人脸。我已经完成了python

     widtho = 717 #width of the given image
     heighto = 562 #height of the given image
     counter = 0
     facecount = 1
     s3 = boto3.resource('s3')
     bucket = s3.Bucket('rek')
     if __name__ == "__main__":
     #Choosing the file in s3 bucket
         photo = 'sl.jpg'
         bucket = 'rek'
     #Intilization of rekognition and performing detect_faces 
     client = boto3.client('rekognition', region_name='eu-west-1')
     response = client.detect_faces(
     Image={'S3Object': {'Bucket': bucket, 'Name': photo}}, Attributes=['ALL'])
     print('Detected faces for ' + photo)
     print('The faces are detected and labled from left to right')
     for faceDetail in response['FaceDetails']:
         print('Face Detected= ', i)
         #To mark a bounding box of the image using coordinates
         print('Bounding Box')
         bboxlen = len(faceDetail['BoundingBox'])
         print(bboxlen)
         width = faceDetail['BoundingBox'].get('Width')
         height = faceDetail['BoundingBox'].get('Height')
         left = faceDetail['BoundingBox'].get('Left')
         top = faceDetail['BoundingBox'].get('Top')
         w = int(width * widtho)
         h = int(height * heighto)
         x = int(left * widtho)
         y = int(top * heighto)
         img2 = image_np[y:h, x:w]
         #now you can push the img2 which is one of the face in the single frame

关于amazon-web-services - 使用 AWS Rekognition 从视频中提取人脸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47919331/

相关文章:

java - 在 aws elastic beanstalk 上上传文件?

java - Spring MVC Hello World 应用程序在 AWS elastic beanstalk 上出现 404 错误,在本地按预期运行

amazon-web-services - AWS CLI S3 : copying file locally using the terminal : fatal error: An error occurred (404) when calling the HeadObject operation

amazon-web-services - 如果更新已经发生,我如何重试 AWS CloudFormation 更新?

javascript - 使用字节的 AWS Rekognition JavaScript SDK

amazon-s3 - 如何检测 Amazon S3 中的变化?

amazon-web-services - 在 CloudFormation 模板中自动设置 ListenerRule 优先级

bash - Shell 脚本 - 根据 ISO 8601 UTC 格式的 'AWS cloudwatch metrics' 属性值对 "Timestamp"json 数组进行排序

amazon-web-services - 用于文本检测的 Amazon Rekognition

amazon-web-services - Amazon Textract与Amazon Rekognition DetectText