ユーザーローカル

姿勢推定AI

APIの利用

POST送信

APIエンドポイント

https://ai-api.userlocal.jp/human_pose

回数制限について

原則1時間あたり100回までです。 API制限を引き上げたい方はお問い合わせ下さい。

APIを叩いた時のresponseヘッダのRETRY-LIMIT-IN-1-HOUR要素に回数が記載されています。

API概要

以下の骨格のパーツそれぞれの座標が一人ずつJsonとなって出力されます。

"Nose", "Neck", "RShoulder", "RElbow", "RWrist", "LShoulder", "LElbow", "LWrist", "RHip", "RKnee", "RAnkle", "LHip", "LKnee", "LAnkle", "REye", "LEye", "REar", "LEar", "BackGround"

一人一人の人物はperson{n}というキーが割り振られます。

送信パラメータ

パラメータ名内容
image_datajpegかpngフォーマットの画像データ(multipart)
response_type

imageかjsonのどちらかを文字列で指定してください。

image: response bodyに骨格を描画した画像が返ってきます。推論結果はヘッダーにあります。

json: json形式で推論結果と画像がbase64エンコードされた状態で返ってきます。

サンプルコード


require 'rest-client'
require 'json'
require 'base64'

url = 'https://ai-api.userlocal.jp/human_pose'

image = File.new('/path/to/image')

params = {
  image_data: image,
  response_type: 'json',
  multipart: true
}

response = RestClient.post(url, params)
data = JSON.parse(response.body)
image = Base64.strict_decode64(data['image_data'])
File.write('out.jpg', image)
puts data['result']

      

import requests
import json
import base64


image_path = "/path/to/image"

image =  open(image_path, "rb").read()
response_type = "json"
request_body = {"response_type": response_type}
url = "https://ai-api.userlocal.jp/human_pose"
res = requests.post(url, data=request_body, files={"image_data": image})
data = json.loads(res.content)
image = base64.b64decode(data["image_data"])
with open("test.jpg", "wb") as f:
    f.write(image)
print(data["result"])


      

<?php
  $target="https://ai-api.userlocal.jp/human_pose";
  # http://php.net/manual/en/curlfile.construct.php
  // Create a CURLFile object / procedural method
  $cfile = curl_file_create("/path/to/image","image/jpeg"); // try adding

  // Assign POST data
  $imgdata = array("image_data" => $cfile, "response_type" => "json");

  $curl = curl_init();
  curl_setopt($curl, CURLOPT_URL, $target);
  curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // stop verifying certificate
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($curl, CURLOPT_POST, true); // enable posting
  curl_setopt($curl, CURLOPT_POSTFIELDS, $imgdata); // post images
  //curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); // if any redirection after upload
  $r = curl_exec($curl);
  curl_close($curl);
  $data = json_decode($r, true);
  $img = base64_decode($data["image_data"]);
  file_put_contents("test.jpg", $img);
  echo var_dump($data["result"]);
?>

      

# test.jpgに対して画像を出力します。verboseオプションをつけることによりヘッダーに書いてある推論結果等も見ることができます。
$ curl --verbose https://ai-api.userlocal.jp/human_pose -F image_data=@path/to/image -F response_type=image > test.jpg
      

# test.jsonに対して推論結果と画像を格納しているjsonを出力します。画像はbase64エンコードされている状態です。
$ curl https://ai-api.userlocal.jp/human_pose -F image_data=@path/to/image -F response_type=json > test.json
      

レスポンス

返却される画像の例

返却されるレスポンス

          
------------------
HEADER
------------------

RETRY-LIMIT-IN-1-HOUR: 98
Content-Type: application/json

------------------
BODY
------------------
{
  "status": "ok",
  "image_data": "base64エンコードされた画像",
  "result": {
    "person1": {
      "BackGround": [264,300],
      "LEar": [545,216],
      "LEye": [518,216],
      .....
      "RKnee": [441,707],
      "RShoulder": [442,317],
      "RWrist": [460,393]
    },
  }
}
          
        
          
------------------
HEADER
------------------
RETRY_LIMIT_IN_1_HOUR: 95
Content-Type: image/jpeg
RESULT: {"person1": {
      "BackGround": [264,300],
      "LEar": [545,216],
      "REye": [487,227],
      .....
      "RKnee": [441,707],
      "RShoulder": [442,317],
      "RWrist": [460,393]
    }}
STATUS: "ok"

------------------
BODY
------------------

JPEG Image Binary

          
        

返却されるJSON内の構造(response_type=jsonのとき)

フィールド形式内容
statusString成功時"ok"。失敗時"error"。
詳細は別表を参照。
image_dataStringbase64エンコードされた骨格検出結果を描画した画像
resultDict推論結果。以下の行の情報を含む。
person{n}Dictn番目の人間を示す。以下の行の情報を含む。
Nose[Number, Number]鼻の座標の推定結果。キーがない場合もあり。
Neck[Number, Number]首の座標の推定結果。キーがない場合もあり。
RShoulder[Number, Number]右肩の座標の推定結果。キーがない場合もあり。
RElbow[Number, Number]右肘の座標の推定結果。キーがない場合もあり。
RWrist[Number, Number]右手首の座標の推定結果。キーがない場合もあり。
LShoulder[Number, Number]左肩の座標の推定結果。キーがない場合もあり。
LElbow[Number, Number]左肘の座標の推定結果。キーがない場合もあり。
LWrist[Number, Number]左手首の座標の推定結果。キーがない場合もあり。
RHip[Number, Number]右尻の座標の推定結果。キーがない場合もあり。
RKnee[Number, Number]右膝の座標の推定結果。キーがない場合もあり。
RAnkle[Number, Number]右足首の座標の推定結果。キーがない場合もあり。
LHip[Number, Number]左尻の座標の推定結果。キーがない場合もあり。
LKnee[Number, Number]左膝の座標の推定結果。キーがない場合もあり。
LAnkle[Number, Number]左足首の座標の推定結果。キーがない場合もあり。
REye[Number, Number]右目の座標の推定結果。キーがない場合もあり。
LEye[Number, Number]左目の座標の推定結果。キーがない場合もあり。
REar[Number, Number]右耳の座標の推定結果。キーがない場合もあり。
LEar[Number, Number]左耳の座標の推定結果。キーがない場合もあり。
BackGround[Number, Number]背景の座標の推定結果。キーがない場合もあり。

エラー出力

statusがerrorの時に以下のようなレスポンスメッセージが発生します

status codeerror typeerror message detail説明
400Bad Requestimage_data is required.image_dataパラメータが必要です。
400Bad Requestresponse_type is required.response_typeパラメータが必要です。
400Bad Requestresponse_type must be json or image.response_typeパラメータはjsonかimageで指定する必要があります。
400Bad RequestFile is not image.アップロードされたファイルが画像でないときに発生するエラーです。
400Bad RequestFile format must be PNG or JPEG.アップロードされたファイルのフォーマットはJPEGかPNGである必要があります。
429Too many requesttoo many request1時間に100回以上のリクエストをすると発生するエラーです。
500Internal server errorInternal server errorサーバー内部でエラーが発生した場合のエラーです。

エラー出力の例


# 複数のバリデーションエラーが発生したケース
{
  status: "error",
  error_type: "Bad Request",
  error_message_detail: [
    "response_type required",
    "image_data required"
  ]
}
      

{
  status: "error",
  error_type: "Bad Request",
  error_message_detail: "File is not image"
}