24 篇文章 5 订阅
51 篇文章 2 订阅
12 篇文章 3 订阅

# 三维姿态控制介绍

1.1  三维姿态估计介绍

1.2  ThreeDPoseUnityBarracuda介绍

ThreeDPoseUnityBarracuda通过读取Barracuda的onnx三维姿态估计模型，可以在Unity上做三维姿态估计。

# 程序设计

2.1 三维姿态估计模型解析

for j in range(0, 24):
# 找到第j个关节的28个特征图，并找到最大值的索引
joint_heat = heatMap3D[j * 28:(j + 1) * 28, ...]
if np.max(joint_heat)>0.1:
print(np.max(joint_heat))
[x, y, z] = np.where(joint_heat == np.max(joint_heat))
x = int(x[-1])
y = int(y[-1])
z = int(z[-1])
# 通过heatmap的索引找到对应的offset图，并计算3D坐标的xyz值
pos_x = offset3D[j * 28 + x, y, z] + x
pos_y = offset3D[24 * 28 + j * 28 + x, y, z] + y
pos_z = offset3D[24 * 28 * 2 + j * 28 + x, y, z] + z
kps[j, 0] = pos_x
kps[j, 1] = pos_y
kps[j, 2] = pos_z
else:
try:
kps[j, 0] = kps[j-1, 0]
kps[j, 0] = kps[j-1, 0]
kps[j, 2] = kps[j-1, 2]
except:
pass
parent = np.array([15, 1, 2, 3, 3, 15, 6, 7, 8, 8, 12, 15, 14, 15, 24, 24, 16, 17, 18, 24, 20, 21, 22, 0]) - 1;
for i in range(len(kps)):
if (parent[i] != -1):
ax.plot3D(kps[[i, parent[i]], 0], -kps[[i, parent[i]], 1], -kps[[i, parent[i]], 2], 'gray')

2.2 unity3D程序设计

Unity3D这里主要使用到了三维场景搭建和CS脚本制定逻辑，这里场景搭建，在搭建好模型后手动规划即可。主要介绍程序部分。

1、读取模型，按照下图配置即可：

2、随机从天空掉落物体CS脚本：

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Randomoccurs : MonoBehaviour
{
//随机产生的物体
private static GameObject sphere;
private static GameObject cube;
private static GameObject cylinder;
private static GameObject capsule;
public GameObject[] gameobject =
{
sphere,
cube,
cylinder,
capsule
};
//想要产生几波
public int waves;
//每波产生的数量
public int values;
//产生之后延迟时间
public float spawnwait ;
// Use this for initialization
void Start()
{
StartCoroutine(test01());
}
void Update()
{
}
// Update is called once per frame
IEnumerator test01()
{
for (int j = 0; j < waves; j++)
{
for (int i = 0; i < values; i++)
{
Instantiate(gameobject[Random.Range(0, 4)], transform.position, transform.rotation);
}
yield return new WaitForSeconds(spawnwait);
}
}
}
3、制定触碰规则，碰到门，门对应ID设置为销毁，碰到掉落物体，分数加分：
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class hit_obj : MonoBehaviour
{
// Start is called before the first frame update
static public int score = 0;
void Start()
{
}
// Update is called once per frame
void Update()
{
}
// 碰撞开始
void OnTriggerEnter(Collider collider)
{
var tag = collider.tag;
if (collider.tag == "body_center")
{
score += 1;
GameObject.Destroy(gameObject);
//GameObject.Destroy(gameObject, 2.0f);//摧毁自身
}
Debug.Log(score);
GameObject.Find("Canvas/Score").GetComponent<Text>().text = "得分："+score.ToString();
if (collider.tag == "ground")
{
//Debug.Log("销毁" + gameObject.tag);
GameObject.Destroy(gameObject);
}
}
// 碰撞结束
void OnTriggerStay(Collider collider)
{
}
// 碰撞持续中
void OnTriggerExit(Collider collider)
{
}
}

https://pan.baidu.com/s/1hZ5f-4Vv12rpJXK5XL_t5A

03-08 3364

09-07 2245
12-09 1236
02-21 4126
04-06 1万+
12-09 3554

### “相关推荐”对你有帮助么？

• 非常没帮助
• 没帮助
• 一般
• 有帮助
• 非常有帮助

AI科技大本营

¥2 ¥4 ¥6 ¥10 ¥20

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、C币套餐、付费专栏及课程。