如何使用amazon rekognition与php比较面孔的信心?

时间:2017-12-12 19:06:06

标签: php amazon-rekognition

我正在使用Amazon重新认知来比较php中的面孔(AWS SDK for php Here文档。

以下代码

<?php
require 'aws.phar';

$s3 = new \Aws\Rekognition\RekognitionClient([
'version' => 'latest',
'region'  => 'us-east-1',
]);

$result = $s3->compareFaces([
    'SimilarityThreshold' => 90,
    'SourceImage' => [
          'Bytes' => file_get_contents("https://images.clarin.com/2017/10/23/BkeLV_s6W_930x525.jpg")        
    ],
    'TargetImage' => [
          'Bytes' => file_get_contents("https://pbs.twimg.com/profile_images/653558348273569792/joxg8DZD_400x400.png")
    ],
]);

?>

我不知道php。 我怎样才能获得图片的信心? 我尝试了一些东西,但我无法得到它。

1 个答案:

答案 0 :(得分:0)

显示如何使用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 Access

$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": []
}

来源:How to use AWS Rekognition to Compare Face in PHP