1

我正在使用 Amazon rekognition 比较 php 中的面孔(AWS SDK for php Here the documentation.

下面的代码

<?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。我怎样才能获得图片的信心?我尝试了一些东西,但我无法得到它。

4

1 回答 1

1

演示如何使用 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 中比较人脸

于 2018-01-07T09:41:14.463 回答