如前所述,我试图将Base64编码的图像传递给AWS API以比较面孔。但是它给了我错误:
An error occurred (InvalidImageFormatException) when calling the CompareFaces operation: Request has invalid image format: InvalidImageFormatException
我之前尝试过使用S3存储桶映像,但它可以正常工作。但是现在我正尝试在不使用S3存储桶的情况下发送图像。
我正在使用Lambda函数,我提到了this documentation
我的代码(编辑版):
source_image_string = "/9j/4......." //Base64 stringified image
target_image_string = "/9j/4A......" //Base64 stringified image
source_byte = base64.b64encode( bytes(source_image_string, "utf-8") )
target_byte = base64.b64encode( bytes(target_image_string, "utf-8") )
response=rekognition.compare_faces(SimilarityThreshold=70,SourceImage={'Bytes': source_byte},TargetImage={'Bytes': target_byte})
我在Cloudwatch中遇到的错误是:
An error occurred (InvalidImageFormatException) when calling the CompareFaces operation: Request has invalid image format: InvalidImageFormatException
Traceback (most recent call last):
File "/var/task/lambda_function.py", line 113, in lambda_handler
raise e
File "/var/task/lambda_function.py", line 105, in lambda_handler
response = compare_faces(source_image_string,target_image_string)
File "/var/task/lambda_function.py", line 43, in compare_faces
response=rekognition.compare_faces(SimilarityThreshold=70,SourceImage={'Bytes': source_byte},TargetImage={'Bytes': target_byte})
File "/var/runtime/botocore/client.py", line 314, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/var/runtime/botocore/client.py", line 612, in _make_api_call
raise error_class(parsed_response, operation_name)
我要去哪里了?我要传递的source_byte
是Byte
格式。
答案 0 :(得分:0)
我这样做是为了编码base64字符串(来自视频帧):
ports:
- containerPort: 8888
name: health-check-port
然后将字节传递为:
buffer = cv2.imencode('.jpg', frame)
image_data = base64.b64encode(buffer)
它工作正常。
似乎您在x_image_string中已经有了b64字符串,我认为这是给您麻烦的格式。