0

在将 aws-sdk 的比较面孔功能与 nodeJS 一起使用时,我们偶尔会看到此错误:

InvalidParameterException: Request has Invalid Parameters
 at Request.extractError (/app/node_modules/aws-sdk/lib/protocol/json.js:48:27)
 at Request.callListeners (/app/node_modules/aws-sdk/lib/sequential_executor.js:105:20)
 at Request.emit (/app/node_modules/aws-sdk/lib/sequential_executor.js:77:10)
 at Request.emit (/app/node_modules/aws-sdk/lib/request.js:683:14)
 at Request.transition (/app/node_modules/aws-sdk/lib/request.js:22:10)     at AcceptorStateMachine.runTo (/app/node_modules/aws-sdk/lib/state_machine.js:14:12)
 at /app/node_modules/aws-sdk/lib/state_machine.js:26:10
 at Request.<anonymous> (/app/node_modules/aws-sdk/lib/request.js:38:9)
 at Request.<anonymous> (/app/node_modules/aws-sdk/lib/request.js:685:12)
 at Request.callListeners (/app/node_modules/aws-sdk/lib/sequential_executor.js:115:18)
 at Request.emit (/app/node_modules/aws-sdk/lib/sequential_executor.js:77:10)
 at Request.emit (/app/node_modules/aws-sdk/lib/request.js:683:14)     at Request.transition (/app/node_modules/aws-sdk/lib/request.js:22:10)
 at AcceptorStateMachine.runTo (/app/node_modules/aws-sdk/lib/state_machine.js:14:12)
 at /app/node_modules/aws-sdk/lib/state_machine.js:26:10
 at Request.<anonymous> (/app/node_modules/aws-sdk/lib/request.js:38:9)
   message: 'Request has Invalid Parameters',
   code: 'InvalidParameterException',
   time: 2018-05-08T15:27:28.188Z,
   requestId: 'XXXXX',
   statusCode: 400,
   retryable: false,
   retryDelay: 52.72405778418885 }

每次使用 iPhone 相机拍摄图像,保存为 JPEG 格式并包含人脸。图像没有损坏,并且已经使用 jpeginfo 进行了测试。然后将它们转换为二进制并通过 sdk 发送到 rekognition。我们通过 python 库 Boto 运行了相同的图像,并成功收到了比较结果。

我们可以在节点端采取进一步的诊断步骤来帮助调试吗?或者对错误原因的任何见解?

更新:

图像尺寸:源:1189 × 750 目标:360 × 480

4

1 回答 1

0

您可以做的一件事是,不是通过您的 javascript 代码直接调用 Rekognition api,而是将您的图像上传到 s3 并将其上传到用 python 编写的 lambda 函数的触发器,lambda 函数将包含比较代码,然后将响应存储在 dynamodb table 作为缓冲区,然后从 dynamodb 获取数据并根据需要使用它。

它看起来是一个漫长的过程,但相信我,我也在使用它,而且它非常简单,并且为我们提供了在后端完成处理的优势,远离天真的用户。

这是比较代码的示例: import boto3 import io from PIL import Image

rekognition = boto3.client('rekognition', region_name='eu-west-1')
dynamodb = boto3.client('dynamodb', region_name='eu-west-1')

image = Image.open("group1.jpeg")
stream = io.BytesIO()
image.save(stream,format="JPEG")
image_binary = stream.getvalue()


response = rekognition.search_faces_by_image(
        CollectionId='family_collection',
        Image={'Bytes':image_binary}                                       
        )

for match in response['FaceMatches']:
    print (match['Face']['FaceId'],match['Face']['Confidence'])

    face = dynamodb.get_item(
        TableName='family_collection',  
        Key={'RekognitionId': {'S': match['Face']['FaceId']}}
        )

    if 'Item' in face:
       print (face['Item']['FullName']['S'])
    else:
       print ('no match found in person lookup')
于 2018-05-18T04:35:39.827 回答