Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.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“;回应[&"x27;面部细节&"x27;];_Python_List_Amazon Web Services_Dictionary_Boto3 - Fatal编程技术网

Python AWS Rekognition“;回应[&"x27;面部细节&"x27;];

Python AWS Rekognition“;回应[&"x27;面部细节&"x27;];,python,list,amazon-web-services,dictionary,boto3,Python,List,Amazon Web Services,Dictionary,Boto3,我遇到了AWS Rekognition python API的问题。有趣的是,我遇到的问题似乎只影响response=client.detect\u facesAPI,因为response=client.detect\u标签不会出现问题。我想做的是只过滤掉我想在程序的下一部分中使用的信息。此代码适用于标签检测: labels1=response['Labels'] extractor=len(labels1) for i in range(0,extractor): print(labe

我遇到了AWS Rekognition python API的问题。有趣的是,我遇到的问题似乎只影响
response=client.detect\u faces
API,因为
response=client.detect\u标签
不会出现问题。我想做的是只过滤掉我想在程序的下一部分中使用的信息。此代码适用于标签检测:

labels1=response['Labels']
extractor=len(labels1)
for i in range(0,extractor):
    print(labels1[diction_counter])
    diction_counter += 1
diction_counter=0
类似的代码将
标签1
定义为包含所有面部细节的列表:

labels1=response['FaceDetails']
当打印该列表时,它会显示一大块信息,这就是它现在应该做的。但是,在请求列表的长度时

print(len(labels1))
我得到的答案是1

在这一点上,我遇到的问题开始了。根据在中找到的FaceDetection的响应结构,
FaceDetails
的响应结构被分成15个字典,其中包含我要查找的信息。但是,我无法使用适用于DetectLables函数的方法来分离字典:

extractor=len(labels1)
for i in range(0,extractor):
    print(labels1[diction_counter])
    diction_counter += 1
原因是python将响应视为长度为1的列表,因此再次显示所有内容。输出如下所示:

[{'BoundingBox': {'Width': 0.23359374701976776, 'Height': 0.41527777910232544, 
'Left': 0.484375, 'Top': 0.125}, 'AgeRange': {'Low': 12, 'High': 22}, 'Smile': 
{'Value': False, 'Confidence': 99.90431213378906}, 'Eyeglasses': {'Value': 
False, 'Confidence': 99.99996185302734}, 'Sunglasses': {'Value': False, 
'Confidence': 98.4183578491211}, 'Gender': {'Value': 'Male', 'Confidence': 
99.9287338256836},...
'AgeRange': {'Low': 12, 'High': 22},
'Smile':{'Value': False, 'Confidence': 99.90431213378906},
'Eyeglasses': {'Value': False, 'Confidence': 99.99996185302734},
'...
我尝试过几种方法,比如将所有这些转换成字符串,然后转换成一个用逗号分隔的列表,但没有任何效果。如果有人对我如何提取某些信息有想法,那么输出结果如下所示:

[{'BoundingBox': {'Width': 0.23359374701976776, 'Height': 0.41527777910232544, 
'Left': 0.484375, 'Top': 0.125}, 'AgeRange': {'Low': 12, 'High': 22}, 'Smile': 
{'Value': False, 'Confidence': 99.90431213378906}, 'Eyeglasses': {'Value': 
False, 'Confidence': 99.99996185302734}, 'Sunglasses': {'Value': False, 
'Confidence': 98.4183578491211}, 'Gender': {'Value': 'Male', 'Confidence': 
99.9287338256836},...
'AgeRange': {'Low': 12, 'High': 22},
'Smile':{'Value': False, 'Confidence': 99.90431213378906},
'Eyeglasses': {'Value': False, 'Confidence': 99.99996185302734},
'...

我将非常感谢任何关于如何实现这一点的提示和技巧。

您没有正确访问变量

DetectFaces检测图像中最大的100个面

因此,您可以执行for循环来访问每个面,如下所示:

response = client.detect_faces()
for faceDetail in response['FaceDetails']:
    box = faceDetail['BoundingBox'] #to get the whole bounding box.
    width = imgWidth * box['Width'] #the width of the bb.
    print('the detected face is between ' + str(faceDetail['AgeRange']['Low']) + ' and' + str(faceDetail['AgeRange']['High']) + ' years old') #access age range low & high
响应语法如下所示:

{
   "FaceDetails": [ 
      { 
         "AgeRange": { 
            "High": number,
            "Low": number
         },
         "Beard": { 
            "Confidence": number,
            "Value": boolean
         },
         "BoundingBox": { 
            "Height": number,
            "Left": number,
            "Top": number,
            "Width": number
         },
         "Confidence": number,
         "Emotions": [ 
            { 
               "Confidence": number,
               "Type": "string"
            }
         ],
         "Eyeglasses": { 
            "Confidence": number,
            "Value": boolean
         },
         "EyesOpen": { 
            "Confidence": number,
            "Value": boolean
         },
         "Gender": { 
            "Confidence": number,
            "Value": "string"
         },
         "Landmarks": [ 
            { 
               "Type": "string",
               "X": number,
               "Y": number
            }
         ],
         "MouthOpen": { 
            "Confidence": number,
            "Value": boolean
         },
         "Mustache": { 
            "Confidence": number,
            "Value": boolean
         },
         "Pose": { 
            "Pitch": number,
            "Roll": number,
            "Yaw": number
         },
         "Quality": { 
            "Brightness": number,
            "Sharpness": number
         },
         "Smile": { 
            "Confidence": number,
            "Value": boolean
         },
         "Sunglasses": { 
            "Confidence": number,
            "Value": boolean
         }
      }
   ],
   "OrientationCorrection": "string"
}
您可以通过以下方式访问其他变量:

emotions = faceDetail['Emotions']

print('Emotion: ' + emotions[0]['Type']) #emotions[0] is for the first face, emotions[1] for the second and so on.

你能澄清你的问题吗?例如,当调用
detect_faces()
时,要提取哪个响应元素?另外,这里有一些使用
检测面()的示例代码。
:您能否发布一个完整的响应,以及您想要什么?看看这是否能帮助您