Memo

メモ > サーバ > サービス: AWS > Amazon Rekognition

■Amazon Rekognition
高精度で物体認識をできる 顔認識&顔認証もできる Amazon Rekognition(高精度の画像・動画分析サービス)| AWS https://aws.amazon.com/jp/rekognition/ Amazon Rekognition をPHPで使って顔のパーツの位置を取得する手順 - Qiita https://qiita.com/nowmura/items/7d6437298e15d7c9d4d4 Amazon Rekognitionを使って顔の部分を切り取る - Qiita https://qiita.com/ran/items/8bdf17d546a3ed1ec440 Amazon Rekognitionで顔認証してみた - Qiita https://qiita.com/OMOIKANESAN/items/c5d1dfe5c00105739dcf Amazon Rekognitionで顔分析LINE BOT - Qiita https://qiita.com/keeey999/items/3f3975770bba1ce19817 Amazon Rekognitionで顔分析LINE BOT - Qiita https://qiita.com/keeey999/items/3f3975770bba1ce19817 Amazon Rekognitionのテキスト検出を利用して、新しいアーキテクチャアイコンのサービス名を取得してみた | Developers.IO https://dev.classmethod.jp/cloud/aws/new-architecture-icon-detect-by-rekognition/ イメージ内のテキストの検出 - Amazon Rekognition https://docs.aws.amazon.com/ja_jp/rekognition/latest/dg/text-detecting-text-procedure.html ■オブジェクトとシーンの検出 以下の記事を参考に試してみたときのメモ Amazon Rekognitionを使いPHPを通してレシピ画像を分析してみる - Qiita https://qiita.com/takenori-ooba/items/4eb8a15ea1a41c5ef1eb コンソール → Amazon Rekognition → デモを試す から、任意の画像をアップロードして検出結果を得ることができる 引き続きSDKからも検証 Vagrantの CentOS7+PHP7.1 環境で試した php-xml が必要だったので追加インストール その後以下のコマンドでAWSのSDKをインストール
$ cd /path/to/directory $ curl -sS https://getcomposer.org/installer | php $ php composer.phar require aws/aws-sdk-php
一例だが、以下のコードで画像を認識できる 人が写っているというだけでなく、「Female」「Smile」のような情報も取得できる
<?php require 'vendor/autoload.php'; use Aws\Rekognition\RekognitionClient; use Aws\Rekognition\Exception\RekognitionException; try { // アクセスキーとシークレットアクセスキーを指定して接続 $rekognition = new RekognitionClient([ 'credentials' => [ 'key' => 'XXXXX', 'secret' => 'YYYYY', ], 'region' => 'ap-northeast-1', 'version' => 'latest', ]); // オブジェクトとシーンの検出 $result = $rekognition->detectLabels([ 'Image' => [ 'Bytes' => file_get_contents('images/female.jpg'), ], ]); print('<pre>'); print_r($result['Labels']); print('</pre>'); exit; } catch (RekognitionException $e) { exit('RekognitionException: ' . $e->getMessage()); } catch (Exception $e) { exit('Exception: ' . $e->getMessage()); }
■顔の分析 一例だが、以下のコードで顔を認識できる
<?php require 'vendor/autoload.php'; use Aws\Rekognition\RekognitionClient; use Aws\Rekognition\Exception\RekognitionException; try { // アクセスキーとシークレットアクセスキーを指定して接続 $rekognition = new RekognitionClient([ 'credentials' => [ 'key' => 'XXXXX', 'secret' => 'YYYYY', ], 'region' => 'ap-northeast-1', 'version' => 'latest', ]); // 顔の分析 $result = $rekognition->detectFaces([ 'Image' => [ 'Bytes' => file_get_contents('images/female.jpg'), ], ]); print('<pre>'); print_r($result['FaceDetails']); print('</pre>'); exit; } catch (RekognitionException $e) { exit('RekognitionException: ' . $e->getMessage()); } catch (Exception $e) { exit('Exception: ' . $e->getMessage()); }
■有名人の認識 一例だが、以下のコードで有名人を認識できる
<?php require 'vendor/autoload.php'; use Aws\Rekognition\RekognitionClient; use Aws\Rekognition\Exception\RekognitionException; try { // アクセスキーとシークレットアクセスキーを指定して接続 $rekognition = new RekognitionClient([ 'credentials' => [ 'key' => 'XXXXX', 'secret' => 'YYYYY', ], 'region' => 'ap-northeast-1', 'version' => 'latest', ]); // 顔の分析 $result = $rekognition->recognizeCelebrities([ 'Image' => [ 'Bytes' => file_get_contents('images/mayu1.jpg'), ], ]); print('<pre>'); print_r($result['CelebrityFaces']); print('</pre>'); exit; } catch (RekognitionException $e) { exit('RekognitionException: ' . $e->getMessage()); } catch (Exception $e) { exit('Exception: ' . $e->getMessage()); }
■顔の比較 一例だが、以下のコードで顔を比較できる
<?php require 'vendor/autoload.php'; use Aws\Rekognition\RekognitionClient; use Aws\Rekognition\Exception\RekognitionException; try { // アクセスキーとシークレットアクセスキーを指定して接続 $rekognition = new RekognitionClient([ 'credentials' => [ 'key' => 'XXXXX', 'secret' => 'YYYYY', ], 'region' => 'ap-northeast-1', 'version' => 'latest', ]); // 顔の比較 $result = $rekognition->compareFaces([ 'SourceImage' => [ 'Bytes' => file_get_contents('images/female1.jpg'), ], 'TargetImage' => [ 'Bytes' => file_get_contents('images/female2.jpg'), ], ]); print('<pre>'); print_r($result['FaceMatches']); print_r($result['UnmatchedFaces']); print('</pre>'); exit; } catch (RekognitionException $e) { exit('RekognitionException: ' . $e->getMessage()); } catch (Exception $e) { exit('Exception: ' . $e->getMessage()); }
■イメージ内のテキスト 一例だが、以下のコードでテキストを認識できる 英語は認識できるが、現時点で日本語は認識できなかった
<?php require 'vendor/autoload.php'; use Aws\Rekognition\RekognitionClient; use Aws\Rekognition\Exception\RekognitionException; try { // アクセスキーとシークレットアクセスキーを指定して接続 $rekognition = new RekognitionClient([ 'credentials' => [ 'key' => 'XXXXX', 'secret' => 'YYYYY', ], 'region' => 'ap-northeast-1', 'version' => 'latest', ]); // イメージ内のテキスト $result = $rekognition->detectText([ 'Image' => [ 'Bytes' => file_get_contents('images/text.png'), ], ]); print('<pre>'); print_r($result['TextDetections']); print('</pre>'); exit; } catch (RekognitionException $e) { exit('RekognitionException: ' . $e->getMessage()); } catch (Exception $e) { exit('Exception: ' . $e->getMessage()); }

Advertisement