随着人工智能技术的不断发展,IT大厂大厂纷纷推出相关产品,如“乐动力”、“天天跳绳”AI运动APP,让云上运动会、线上运动会、健身打卡、AI体育指导等概念空前火热。那么,能否将这些在APP成功应用的场景搬上小程序,分享这些概念的红利呢?本系列文章就带您一步一步从零开始开发一个AI运动小程序,本系列文章将使用“云智AI运动识别小程序插件”,请先行在微信服务市场或官网了解详情。
在姿态、动作、运动检测时,采用检测规则计算器虽然非常便捷了,但是为了进一步减少开发者在运动适配中的工作量,方案还提供了一个姿态动作相似度比较功能,本篇就为您介绍此功能的运用。
一、采集样本动作帧
在进行姿态比较前,需要采集样本动作帧的人体关键点数据,采集样本帧推荐使用们的“姿态调试的辅助桌面工具”,具体使用请参考上篇工具的使用。
二、执行姿态比较
姿态相似度比较能力由calc.PoseComparer
类提供。
//样本动作人体关键点
const sample =
[{
y:95.41808288282594,x:214.42673274576924,score:0.51611328125,name:"nose"},
{
y:84.61684727250136,x:221.80983627909686,score:0.7265625,name:"left_eye"},
{
y:87.59059985661885,x:202.12153237356293,score:0.59130859375,name:"right_eye"},
{
y:92.85449529945058,x:234.93538334278358,score:0.814453125,name:"left_ear"},
{
y:99.07546188234281,x:188.58581196413604,score:0.6806640625,name:"right_ear"},
{
y:149.86859452983884,x:271.3040866650822,score:0.7246093153953552,name:"left_shoulder"},
{
y:162.78905492065545,x:158.09624324078422,score:0.82666015625,name:"right_shoulder"},
{
y:236.41516213602512,x:280.8747980656871,score:0.728515625,name:"left_elbow"},
{
y:246.8062369181066,x:156.3188420992395,score:0.55859375,name:"right_elbow"},
{
y:305.46100866896046,x:286.61722490605007,score:0.6591796875,name:"left_wrist"},
{
y:313.80120003234475,x:152.9006975047454,score:0.70849609375,name:"right_wrist"},
{
y:304.5039375289,x:251.342317172392,score:0.87646484375,name:"left_hip"},
{
y:303.68360752741575,x:189.6796075527766,score:0.8740234375,name:"right_hip"},
{
y:431.38422581120494,x:237.66987231438497,score:0.70703125,name:"left_knee"},
{
y:430.01698132540423,x:189.6796075527766,score:0.8017578125,name:"right_knee"},
{
y:529.8258287888553,x:229.19295650242066,score:0.6884765625,name:"left_ankle"},
{
y:534.747908937738,x:201.71134233782658,score:0.578125,name:"right_ankle"}];
//当前帧动作
const frame =
[{
y:154.06250001297832,x:258.7499999883252,score:0.728515625,name:"nose"},
{
y:143.12500001305142,x:254.37499998835446,score:0.56298828125,name:"left_eye"},
{
y:143.75001908653357,x:255.937499988344,score:0.69482421875,name:"right_eye"},
{
y:143.984394086532,x:229.99999998851743,score:0.43115234375,name:"left_ear"}
,{
y:146.17187501303107,x:236.09374998847667,score:0.4919433891773224,name:"right_ear"},
{
y:201.4062690861481,x:205.9375190621646,score:0.51416015625,name:"left_shoulder"},
{
y:202.03125001265758,x:227.96874998853102,score:0.66259765625,name:"right_shoulder"},
{
y:281.25001908561427,x:234.6874999884861,score:0.26416015625,name:"left_elbow"},
{
y:270.6250190856853,x:254.06249998835656,score:0.278076171875,name:"right_elbow"},
{
y:246.09376908584932,x:289.06249998812257,score:0.1997070610523224,name:"left_wrist"},
{
y:238.43750001241418,x:300.62499998804526,score:0.50927734375,name:"right_wrist"},
{
y:321.5624618648858,x:218.59376906208004,score:0.58154296875,name:"left_hip"},
{
y:323.43750001184594,x:224.06249998855716,score:0.5615234375,name:"right_hip"},
{
y:453.43750001097675,x:217.34376906208837,score:0.6103515625,name:"left_knee"},
{
y:455.6250000109622,x:214.06249998862396,score:0.51416015625,name:"right_knee"},
{
y:572.5000000101808,x:215.31249998861563,score:0.403564453125,name:"left_ankle"},
{
y:593.1250000100429,x:216.0937499886104,score:0.52294921875,name:"right_ankle"}];
//新建比较器,比较
const AiSport = requirePlugin("aiSport");
const poseComparer = new AiSport.calc.PoseComparer();
const result = poseComparer.compare(sample, frame);
console.log(result);
//输出结果
//{items:
// [{key:"head",score:0.4327263684686711,summary:"头部偏转相似度"},
// {key:"trunk",score:0.8407704975917485,summary:"躯干形态相似度"},
// {key:"left_hand",score:0.2155245751055277,summary:"左手相似度"},
// {key:"right_hand",score:0.21361728579451628,summary:"左手相似度"},
// {key:"left_foot",score:0.5147016736506456,summary:"左脚相似度"},
// {key:"right_foot",score:0.5190758118853293,summary:"右脚相似度"}],
// score:0.5110266728697409
//}
三、在组合运动中的应用
有的运动不只一个动作,比如开合跳,可以拆解成开、合两个动作,分别取样本帧,进行比较即可;如果是局部脚体动作,可以不取整体评分,可以取指定肢体相似度值进行比较。