LoginSignup
3
4

More than 5 years have passed since last update.

人の顔を解析する便利なAPI

Last updated at Posted at 2018-01-22

はじめに

最近、iPhoneXで顔認証が使われてたりと顔の画像解析技術が注目を集めています、
そこで顔の画像解析で優秀なAPIがあったので紹介します。
中国で作られたAPIで「face++」というものです。
まずは、簡単な使い方から紹介します。

APIKeyの取得

はじめに、sign upを行い、API KEYを取得してください
https://www.faceplusplus.com/

アカウントを作成し、
Apps > API KeyのGet API Keyから作成できます
スクリーンショット 2018-01-21 14.09.07.png

作成が完了すると以下のような画面になります。
スクリーンショット 2018-01-21 16.29.31.png

APIを叩いてみる

API keyが取得できたら早速APIを叩いてみます

簡単な情報だけ取得

まずは、以下の様な形式でAPIを叩きます

$ curl -X POST "https://api-us.faceplusplus.com/facepp/v3/detect" -F "api_key=<api key>" \
-F "api_secret<api secret>" \
-F "image_url=<顔の入った写真のURL>" \

すると以下のようなjsonが返ってきます

{
    "faces": [
        {
            "face_rectangle": {
                "height": 112, 
                "left": 51, 
                "top": 85, 
                "width": 112
            }, 
            "face_token": "20c31e814a28ab03c8edb793c793f717"
        }
    ], 
    "image_id": "6STR0Wfxj826JYSX0t5gcg==", 
    "request_id": "1516518682,707235fb-1129-4f54-8853-2870e386a52b", 
    "time_used": 1287
}

さらに細かい情報を取得する

return_landmark = 1を加えればもっと細かい情報まで取得できます。

$ curl -X POST "https://api-us.faceplusplus.com/facepp/v3/detect" -F "api_key=<api key>" \
-F "api_secret<api secret>" \
-F "image_url=<顔の入った写真のURL>" \
-F "return_landmark=1"

たくさんの結果が返ってくるため省略して一部を示しますが、鼻だけでこれだけ座標が取得できます!
境界線まで細かく返ってきます。

"nose_contour_left2":{"x":98,"y":126},
"nose_contour_left3":{"x":102,"y":138},
"nose_contour_lower_middle":{"x":110,"y":139},
"nose_contour_right1":{"x":115,"y":107},
"nose_contour_right2":{"x":120,"y":125},
"nose_contour_right3":{"x":117,"y":137},
"nose_left":{"x":95,"y":135},
"nose_right":{"x":124,"y":133},
"nose_tip":{"x":111,"y":129},

めっちゃ優秀ですね!!
鼻以外にも目など様々な座標が返ってきます。
返却値の詳細はここに記載されています。
https://console.faceplusplus.com/documents/13207488

画像の年齢や性別などを当ててもらう

さらに、return_attributesを加えればその他の情報も取得できます。
例えば、年齢と性別を判断して返してくれます。

 $ curl -X POST "https://api-us.faceplusplus.com/facepp/v3/detect" -F "api_key=<api key>" \
-F "api_secret<api secret>" \
-F "image_url=<顔の入った写真のURL>" \
-F "return_landmark=1" \
-F "return_attributes=gender,age"

こんな感じで返ってきます

"attributes": {
  "age": {
    "value": 36
  }, 
  "gender": {
    "value": "Male"
  }
}

その他のoptionについては以下のドキュメントをご参照ください
https://console.faceplusplus.com/documents/5679127

3
4
0

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
  3. You can use dark theme
What you can do with signing up
3
4