我正在使用 Amazon Rekognition 比较加载到 python 内存中的图像之间的人脸,但是当我尝试传递裁剪的图像时,它会引发错误:
InvalidParameterException: An error occurred (InvalidParameterException) when calling the CompareFaces operation: Request has Invalid Parameters
正在使用的代码示例是:
ret, frame = vid.read()
frame = cv2.resize(frame1, (0,0), fx=.5, fy=.5)
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
content1 = cv2.imencode('.jpg',frame[:,0:540,:])[1].tostring()
content2 = cv2.imencode('.jpg',frame[:,1:540,:])[1].tostring()
awsclient=boto3.client('rekognition','us-west-2',
aws_access_key_id='********************',
aws_secret_access_key='*****************')
awsresponse = awsclient.compare_faces(SourceImage={'Bytes': content1},
TargetImage={'Bytes': content2})
最后一行抛出错误。但是,如果我提交:
awsresponse = awsclient.compare_faces(SourceImage={'Bytes': content1},
TargetImage={'Bytes': content1})
没有错误,人脸匹配。有没有人知道这个错误的原因?
此错误的完整跟踪:
---------------------------------------------------------------------------
InvalidParameterException Traceback (most recent call last)
<ipython-input-227-60437107e6df> in <module>()
8 aws_secret_access_key='***********')
9 awsresponse = awsclient.compare_faces(SourceImage={'Bytes': content1},
---> 10 TargetImage={'Bytes': content2})
/usr/local/lib/python3.5/dist-packages/botocore/client.py in _api_call(self, *args, **kwargs)
312 "%s() only accepts keyword arguments." % py_operation_name)
313 # The "self" in this scope is referring to the BaseClient.
--> 314 return self._make_api_call(operation_name, kwargs)
315
316 _api_call.__name__ = str(py_operation_name)
/usr/local/lib/python3.5/dist-packages/botocore/client.py in _make_api_call(self, operation_name, api_params)
610 error_code = parsed_response.get("Error", {}).get("Code")
611 error_class = self.exceptions.from_code(error_code)
--> 612 raise error_class(parsed_response, operation_name)
613 else:
614 return parsed_response
InvalidParameterException: An error occurred (InvalidParameterException) when calling the CompareFaces operation: Request has Invalid Parameters