演示如何使用 Aws\Rekognition\RekognitionClient 对象来调用比较面操作。PHP:
使用识别客户端
require 'vendor/aws/aws-autoloader.php';
use Aws\Rekognition\RekognitionClient;
用于访问 AWS 服务代码参数的凭证
$credentials = new Aws\Credentials\Credentials('{AWS access key ID}', '{AWS secret access key}');
获取 Rekognition 访问权限
$rekognitionClient = RekognitionClient::factory(array(
'region' => "us-east-1",
'version' => 'latest',
'credentials' => $credentials
));
调用比较人脸功能
$compareFaceResults= $rekognitionClient->compareFaces([
'SimilarityThreshold' => 80,
'SourceImage' => [
'Bytes' => file_get_contents("SourceImage.jpg")
],
'TargetImage' => [
'Bytes' => file_get_contents("TargetImage.jpg")
],
]);
响应 JSON 数据
$FaceMatchesResult = $compareFaceResults['FaceMatches'];
$SimilarityResult = $FaceMatchesResult['Similarity'] //Here You will get similarity
$sourceImageFace = $compareFaceResults['SourceImageFace']
$sourceConfidence = $sourceImageFace['Confidence'] // //Here You will get confidence of the picture
注意:AWS 结果示例:-
{
"SourceImageFace": {
"BoundingBox": {
"Width": 0.4662500023841858,
"Height": 0.6998124122619629,
"Left": 0.5024999976158142,
"Top": 0.09849905967712402
},
"Confidence": 99.99332427978516
},
"FaceMatches": [
{
"Similarity": 93,
"Face": {
"BoundingBox": {
"Width": 0.23999999463558197,
"Height": 0.3602251410484314,
"Left": 0.43937501311302185,
"Top": 0.17823639512062073
},
"Confidence": 99.99273681640625,
"Landmarks": [
{
"Type": "eyeLeft",
"X": 0.5512950420379639,
"Y": 0.32593753933906555
}
....................
....................
],
"Pose": {
"Roll": 13.300010681152344,
"Yaw": 48.84736251831055,
"Pitch": -11.894044876098633
},
"Quality": {
"Brightness": 45.3167610168457,
"Sharpness": 99.99671173095703
}
}
},
"UnmatchedFaces": []
}
来源:如何使用 AWS Rekognition 在 PHP 中比较人脸