search
LoginSignup
8
Help us understand the problem. What are the problem?

More than 3 years have passed since last update.

posted at

updated at

Amazon Rekognition をPHPで使って顔のパーツの位置を取得する手順

Amazon Rekognition
https://aws.amazon.com/jp/rekognition/

IAM作成

http://docs.aws.amazon.com/ja_jp/rekognition/latest/dg/setting-up.html
上記を参考にIAMを作る。


1.png

2.png

3.png

5.png

PHP7 + AWS SDK for PHP 3(aws.phar) + base64画像

S3上のファイルを指定することもできるようです。

$image = $_POST['image']; //base64エンコードされた画像
$image = explode(',', $image);
$image = $image[ count($image)-1 ];
$image = base64_decode($image);

require('aws.phar');

$o_awsRekognition = new Aws\Rekognition\RekognitionClient([
    'credentials' => array(
        'key'   => '{IAM作成時に取得したAccess key ID}',
        'secret'=> '{IAM作成時に取得したSecret access key}'
    ),
    'region'    => 'us-east-1', //北バージニア。アジアリージョン未対応
    'version'   => 'latest'
]);

$result = $o_awsRekognition->detectFaces([
    'Attributes'=> ['DEFAULT'],  //ALL|DEFAULT。ALLだと重い
    'Image'     => [
        'Bytes' => $image
    ]
]);
$result = (array)$result;

foreach ($result as $line) {
    $result = $line;
    break;
}

$result = json_encode($result);
print $result;

結果

http://docs.aws.amazon.com/rekognition/latest/dg/API_DetectFaces.html
Response Syntax参照。

送信した画像はamazon側で保存されるの?

https://aws.amazon.com/jp/rekognition/faqs/
データプライバシーを見る限りされなさそう。

参考URL

http://docs.aws.amazon.com/rekognition/latest/dg/what-is.html
http://docs.aws.amazon.com/rekognition/latest/dg/rekognition-dg.pdf
http://docs.aws.amazon.com/rekognition/latest/dg/API_DetectFaces.html
http://docs.aws.amazon.com/aws-sdk-php/v3/api/api-rekognition-2016-06-27.html#detectfaces
http://docs.aws.amazon.com/ja_jp/rekognition/latest/dg/setting-up.html
http://docs.aws.amazon.com/aws-sdk-php/v3/api/class-Aws.Result.html

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
What you can do with signing up
8
Help us understand the problem. What are the problem?