unity+kinect 获取人物数据信息存入本地txt
程序员文章站
2022-05-13 15:08:27
...
1.定义关节点信息
2.与人物场景对齐
将kinect 获取到的真实关节点信息赋值给场景中的人物
3.获取三维信息(一个示例,也可获取距离,角度,根据自己的需求)
4.存入本地
4.1 在本地建立txt文件夹
4.2unity代码读取
string ReadFile(string PathName, int linenumber)
{
string[] strs = File.ReadAllLines(PathName);//读取txt文本的内容,返回sring数组的元素是每行内容
int row = strs.Length; //行数
Debug.Log(row);
if (linenumber == 0)
{
return "";
}
else
{
return strs[linenumber - 1]; //返回第linenumber行内容
}
}
4.3本地文件中写入unity运行产生的数据
ReadFile("D:\\sanwei.txt", 1);
File.AppendAllText("D:\\sanwei.txt", "time: ");
File.AppendAllText("D:\\sanwei.txt", string.Format("{0:D2}:{1:D2}:{2:D2}:{3:D3}",
hour, minute, second, milliScecond) + " ");
File.AppendAllText("D:\\sanwei.txt", " " + "\n\r");//换行
File.AppendAllText("D:\\sanwei.txt", "SpineBase: " + SpineBase0);
File.AppendAllText("D:\\sanwei.txt", " " + "\n\r");//换行
File.AppendAllText("D:\\sanwei.txt", " SpineMid: " + SpineMid1);
File.AppendAllText("D:\\sanwei.txt", " " + "\n\r");//换行
File.AppendAllText("D:\\sanwei.txt", " Head: " + Head3);
File.AppendAllText("D:\\sanwei.txt", " " + "\n\r");//换行
File.AppendAllText("D:\\sanwei.txt", " LeftShoulder: " + LeftShoulder4);
File.AppendAllText("D:\\sanwei.txt", " " + "\n\r");//换行
File.AppendAllText("D:\\sanwei.txt", " LeftElbow: " + LeftElbow5);
File.AppendAllText("D:\\sanwei.txt", " " + "\n\r");//换行
File.AppendAllText("D:\\sanwei.txt", " LeftWrist: " + LeftWrist6);
File.AppendAllText("D:\\sanwei.txt", " " + "\n\r");//换行
File.AppendAllText("D:\\sanwei.txt", " LeftHand: " + LeftHand7);
File.AppendAllText("D:\\sanwei.txt", " " + "\n\r");//换行
File.AppendAllText("D:\\sanwei.txt", " RightShoulder: " + RightShoulder8);
File.AppendAllText("D:\\sanwei.txt", " " + "\n\r");//换行
File.AppendAllText("D:\\sanwei.txt", " RightElbow: " + RightElbow9);
File.AppendAllText("D:\\sanwei.txt", " " + "\n\r");//换行
File.AppendAllText("D:\\sanwei.txt", " RightWrist: " + RightWrist10);
File.AppendAllText("D:\\sanwei.txt", " " + "\n\r");//换行
File.AppendAllText("D:\\sanwei.txt", " RightHand: " + RightHand11);
File.AppendAllText("D:\\sanwei.txt", " " + "\n\r");//换行
File.AppendAllText("D:\\sanwei.txt", " LeftHip: " + LeftHip12);
File.AppendAllText("D:\\sanwei.txt", " " + "\n\r");//换行
File.AppendAllText("D:\\sanwei.txt", " LeftKnee: " + LeftKnee13);
File.AppendAllText("D:\\sanwei.txt", " " + "\n\r");//换行
File.AppendAllText("D:\\sanwei.txt", " LeftAnkle: " + LeftAnkle14);
File.AppendAllText("D:\\sanwei.txt", " " + "\n\r");//换行
File.AppendAllText("D:\\sanwei.txt", " LeftFoot: " + LeftFoot15);
File.AppendAllText("D:\\sanwei.txt", " " + "\n\r");//换行
File.AppendAllText("D:\\sanwei.txt", " RightHip: " + RightHip16);
File.AppendAllText("D:\\sanwei.txt", " " + "\n\r");//换行
File.AppendAllText("D:\\sanwei.txt", " RightKnee: " + RightKnee17);
File.AppendAllText("D:\\sanwei.txt", " " + "\n\r");//换行
File.AppendAllText("D:\\sanwei.txt", " RightAnkle: " + RightAnkle18);
File.AppendAllText("D:\\sanwei.txt", " " + "\n\r");//换行
File.AppendAllText("D:\\sanwei.txt", " RightFoot: " + RightFoot19);
File.AppendAllText("D:\\sanwei.txt", " " + "\n\r");//换行
File.AppendAllText("D:\\sanwei.txt", " Spineshoulder: " + Spineshoulder20);
File.AppendAllText("D:\\sanwei.txt", " " + "\n\r");//换行
File.AppendAllText("D:\\sanwei.txt", " LeftHandTip: " + LeftHandTip21);
File.AppendAllText("D:\\sanwei.txt", " " + "\n\r");//换行
File.AppendAllText("D:\\sanwei.txt", " LeftThumb: " + LeftThumb22);
File.AppendAllText("D:\\sanwei.txt", " " + "\n\r");//换行
File.AppendAllText("D:\\sanwei.txt", " RightHandtip: " + RightHandtip23);
File.AppendAllText("D:\\sanwei.txt", " " + "\n\r");//换行
File.AppendAllText("D:\\sanwei.txt", " RightThumb: " + RightThumb24);
// File.AppendAllText("D:\\sanwei.txt", " " + "\n\r");
File.AppendAllText("D:\\sanwei.txt", " " + "\n\r");//换行
#endregion
5.效果展示
上一篇: Kinect V2开发(5)读关节数据
下一篇: Kinect V2开发(5)绘制骨架图