クリエイターの教科書

ChatGPT, Stable Diffusion, Visual Studio, Excelなど教科書

写真から無料でスケルトン(骨格)を取得するには?~姿勢推定API

野球やゴルフなどでは、スイング姿勢として骨格情報を取りたい場合があります。

現状、この処理はマシンパワーをかなり使うこともあって、いいAPIはありません。

しかしAI処理でおなじみユーザローカルが、姿勢取得APIを公開。今のところ無料で医療可能となっています。

姿勢取得APIとは?

写真から人の骨格ースケルトンを取得してくれるAPIです。

 

スケルトンがわかると、野球やゴルフのスイング解析などがしやすくなります。

 

人工知能などに取り組んでいるユーザローカルから無料公開されています。

 

 

使い方は?

サイトで試す

以下サイトへアクセス。

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

f:id:apicode:20200110150222p:plain

 

画像をフリーサイトぱくたそなどからゲットしておきます。

https://www.pakutaso.com/20181042277post-17873.html

f:id:apicode:20200110150336j:plain

 

写真をサイトへアップすると瞬時に以下のように変換してくれます。

f:id:apicode:20200110150338p:plain

 

変換時間はあっというまでした。

 

現在は生成画像のみなので、スイング画像を1つづつ処理してみました。 

チキンウィングのスイングポーズのほうがわかりよかったかもしれません。

f:id:apicode:20200110152242j:plain

f:id:apicode:20200110152246j:plain

f:id:apicode:20200110152250j:plain

f:id:apicode:20200110152253j:plain

f:id:apicode:20200110152255j:plain

f:id:apicode:20200110152258j:plain

f:id:apicode:20200110152301j:plain

 

 

開発者用APIを利用するには?

https://ai-api.userlocal.jp/human_pose」でAPIへアクセス可能。

 

画像をmultipartのデータとして送信すると、「"Nose", "Neck", "RShoulder", "RElbow", "RWrist", "LShoulder", "LElbow", "LWrist", "RHip", "RKnee", "RAnkle", "LHip", "LKnee", "LAnkle", "REye", "LEye", "REar", "LEar", "BackGround"」といったポジションの情報を取得できます。

 

1時間で100回以内とされており、制限は緩やかなほうだと思います。

https://humanpose-ai.userlocal.jp/human_pose/document

 

実際に上記の写真を送ってみると以下のようなJSONファイルが取得できます。

array(1) { ["person1"]=> array(17) { ["LAnkle"]=> array(2) { [0]=> int(734) [1]=> int(935) } ["LEar"]=> array(2) { [0]=> int(663) [1]=> int(421) } ["LElbow"]=> array(2) { [0]=> int(705) [1]=> int(545) } ["LEye"]=> array(2) { [0]=> int(638) [1]=> int(435) } ["LHip"]=> array(2) { [0]=> int(703) [1]=> int(618) } ["LKnee"]=> array(2) { [0]=> int(725) [1]=> int(778) } ["LShoulder"]=> array(2) { [0]=> int(714) [1]=> int(428) } ["LWrist"]=> array(2) { [0]=> int(691) [1]=> int(641) } ["Neck"]=> array(2) { [0]=> int(652) [1]=> int(451) } ["Nose"]=> array(2) { [0]=> int(627) [1]=> int(445) } ["RAnkle"]=> array(2) { [0]=> int(523) [1]=> int(938) } ["RElbow"]=> array(2) { [0]=> int(613) [1]=> int(591) } ["REye"]=> array(2) { [0]=> int(624) [1]=> int(435) } ["RHip"]=> array(2) { [0]=> int(627) [1]=> int(628) } ["RKnee"]=> array(2) { [0]=> int(585) [1]=> int(788) } ["RShoulder"]=> array(2) { [0]=> int(590) [1]=> int(475) } ["RWrist"]=> array(2) { [0]=> int(661) [1]=> int(665) } } }

 

サンプルとしてPHPやPYTHONが公開されています。

 

 

「1.jpg」を送る場合のソースは以下の通り。

スケルトンが書き込まれた画像ファイルも取得可能で、以下のソースでは「2.jpg」と書いているところが取得したスケルトン画像のファイル名になります。

 

<?php
$target="https://ai-api.userlocal.jp/human_pose";
$cfile = curl_file_create("1.jpg","image/jpeg"); // try adding
$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
$r = curl_exec($curl);
curl_close($curl);
$data = json_decode($r, true);
$img = base64_decode($data["image_data"]);
file_put_contents("2.jpg", $img);
echo var_dump($data["result"]);
?>

 

 

 JavaScriptでも使える?

試してませんが画像データをサーバへ送るだけなので、JavaScriptでもスケルトン情報や画像の取得は可能ではないかと思います。

 

 

ゴルフのスイング分析

ゴルフでは、姿勢の情報からチキンウィングかどうかといったスイング判定もしやすくなります。 

komatter.com

このブログは、ネットや書籍上の情報、個人の体験や感想を中心にまとめたものです。 正確性を期していはいますが、間違い・誤訳等あるかもしれません。 当サイトの情報によって生じたいかなる損失について一切の責任を負わないものとします. あらかじめご了承ください。

プライバシーポリシー |〇利用規約 |〇問い合わせ