首页 > 解决方案 > aws rekognition 打印边界框

问题描述

我正在尝试从边界框打印内容,问题是,如果图像有两个或更多面孔,则作业将返回两个或更多边界框,那么我将如何打印出来?

我试图编写一个循环来读取 str 'BoundingBox' 并打印,但它只返回第一个边界框两次。谁能给我一些想法?谢谢你

i=0
for bBox in response:
    print('found face at...')
    bBox = response['FaceDetails'][i]['BoundingBox']
    print("BoundingBox: ({}%)".format(bBox['Width']))
    print("BoundingBox: ({}%)".format(bBox['Height']))
    print("BoundingBox: ({}%)".format(bBox['Left']))
    print("BoundingBox: ({}%)".format(bBox['Top']))
    i+=i

格式为:

{'FaceDetails': [
{
'BoundingBox': 
    {'Width': 0.49861112236976624, 'Height': 0.2796874940395355, 'Left': 0.43611112236976624, 'Top': 0.27656251192092896}, 
'Landmarks': [
    {'Type': 'eyeLeft', 'X': 0.6100848913192749, 'Y': 0.394705593585968}, 
    {'Type': 'eyeRight', 'X': 0.7668542861938477, 'Y': 0.4047696590423584}, 
    {'Type': 'nose', 'X': 0.6669187545776367, 'Y': 0.45966070890426636}, 
    {'Type': 'mouthLeft', 'X': 0.5887312293052673, 'Y': 0.4715222418308258}, 
    {'Type': 'mouthRight', 'X': 0.7437177896499634, 'Y': 0.4851195216178894}
        ], 
'Pose': 
    {'Roll': 6.393648624420166, 'Yaw': -2.539684772491455, 'Pitch': -15.155187606811523}, 
'Quality': 
    {'Brightness': 48.02949905395508, 'Sharpness': 99.99090576171875}, 
'Confidence': 99.99468994140625}, 

{
'BoundingBox': 
    {'Width': 0.3791666626930237, 'Height': 0.21328124403953552, 'Left': 0.12638889253139496, 'Top': 0.29765623807907104}, 
'Landmarks': [
    {'Type': 'eyeLeft', 'X': 0.26656731963157654, 'Y': 0.3757162392139435}, 
    {'Type': 'eyeRight', 'X': 0.4015311002731323, 'Y': 0.39424583315849304}, 
    {'Type': 'nose', 'X': 0.31936877965927124, 'Y': 0.4345789849758148}, 
    {'Type': 'mouthLeft', 'X': 0.2394552081823349, 'Y': 0.4479488432407379}, 
    {'Type': 'mouthRight', 'X': 0.3651302456855774, 'Y': 0.4635950028896332}
        ], 
'Pose': 
    {'Roll': 13.218778610229492, 'Yaw': 5.575412273406982, 'Pitch': -11.283287048339844}, 
'Quality': 
    {'Brightness': 50.93876647949219, 'Sharpness': 99.98487854003906}, 
'Confidence': 99.99580383300781}
], 
'ResponseMetadata': 
{
    'RequestId': '24170e12-4c08-11e8-92d8-4be404513e1e', 
    'HTTPStatusCode': 200, 
    'HTTPHeaders': 
        {
        'content-type': 'application/x-amz-json-1.1', 
        'date': 'Sun, 29 Apr 2018 23:50:48 GMT', 
        'x-amzn-requestid': '24170e12-4c08-11e8-92d8-4be404513e1e', 
        'content-length': '1340', 'connection': 'keep-alive'
        }, 
'RetryAttempts': 0
}
}

这是它返回的内容:

found face at...
BoundingBox: (0.49861112236976624%)
BoundingBox: (0.2796874940395355%)
BoundingBox: (0.43611112236976624%)
BoundingBox: (0.27656251192092896%)
found face at...
BoundingBox: (0.49861112236976624%)
BoundingBox: (0.2796874940395355%)
BoundingBox: (0.43611112236976624%)
BoundingBox: (0.27656251192092896%)

标签: pythonamazon-web-servicesaws-sdkamazon-rekognition

解决方案


for face in response['FaceDetails']:
    print ('Face found at...')
    box = face['BoundingBox']
    for key,value in box.items():
        print key, value

回报:

Face found at...
Width 0.49861112237
Top 0.276562511921
Left 0.43611112237
Height 0.27968749404
Face found at...
Width 0.379166662693
Top 0.297656238079
Left 0.126388892531
Height 0.21328124404

推荐阅读