- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 kinect sdk v1.7 的新手。
我想知道如何从样本中捕捉运动数据。( http://msdn.microsoft.com/en-us/library/jj131041.aspx )
那么,我怎样才能制作一个可以将骨架数据捕获到文件中的程序呢? (记录)
然后,将文件读回示例程序并对其建模。(播放)?
我的想法是将骨架数据记录到文件中,然后从文件中获取骨架数据并让Avatar播放。
我可以在另一个示例程序中做我想做的事。 ( http://msdn.microsoft.com/en-us/library/hh855381 ) ,导致示例程序只绘制线和骨架点。
例如,
00001 00:00:00.0110006@353,349,354,332,358,249,353,202,310,278,286,349,269,407,266,430,401,279,425,349,445,408,453,433,332,369,301,460,276,539,269,565,372,370,379,466,387,548,389,575,
00002 00:00:00.0150008@352,349,353,332,356,249,352,202,309,278,284,349,266,406,263,430,398,279,424,349,445,408,453,433,331,369,301,461,277,541,271,566,371,371,379,466,387,548,390,575,
[帧号][时间戳]@[骨架位置坐标]
在这个例子中,我假设骨架位置是关节 ID 顺序。
谢谢(请原谅我糟糕的英语)。
最佳答案
你可以使用一个StreamWriter
,在选择的路径初始化它,然后对于每一帧,增加帧计数器,将它写入文件,将时间戳写入文件,然后循环遍历关节并将它们写入文件。我会这样做:
using System.IO;
StreamWriter writer = new StreamWriter(@path);
int frames = 0;
...
void AllFramesReady(object sender, AllFramesReadyEventArgs e)
{
frames++;
using (SkeletonFrame sFrame = e.OpenSkeletonFrameData())
{
if (sFrame == null)
return;
skeletonFrame.CopySkeletonDataTo(skeletons);
Skeleton skeleton = (from s in skeletons
where s.TrackingState == SkeletonTrackingState.Tracked
select s);
if (skeleton == null)
return;
if (skeleton.TrackingState == SkeletonTrackingState.Tracked)
{
writer.Write("{0} {1}@", frames, timestamp);//I dont know how you want to do this
foreach (Joint joint in skeleton.Joints)
{
writer.Write(joint.Position.X + "," + joint.Position.Y + "," joint.Position.Z + ",");
}
writer.Write(Environment.NewLine);
}
}
}
然后从文件中读取:
StreamReader reader = new StreamReader(@path);
int frame = -1;
JointCollection joints;
...
string[] lines = reader.ReadAllLines();
...
void AllFramesReady(object sender, AllFramesReadyEventArgs e)
{
canvas.Children.Clear();
string[] coords = lines[frame].Split('@')[1].Split(',');
int jointIndex = 0;
for (int i = 0; i < coords.Length; i += 3)
{
joints[jointIndex].Position.X = int.Parse(coords[i]);
joints[jointIndex].Position.Y = int.Parse(coords[i + 1]);
joints[jointIndex].Position.X = int.Parse(coords[i + 2]);
jointIndex++;
}
DepthImageFrame depthFrame = e.OpenDepthImageFrame();
canvas.Children.Add(GetBodySegment(joints, brush, new JointType[] { JointType.HipCenter, JointType.Spine, JointType.ShoulderCenter, JointType.Head }, depthFrame, canvas));
canvas.Children.Add(GetBodySegment(joints, brush, new JointType[] { JointType.ShoulderCenter, JointType.ShoulderLeft, JointType.ElbowLeft, JointType.WristLeft, JointType.HandLeft }, depthFrame, canvas));
canvas.Children.Add(GetBodySegment(joints, brush, new JointType[] { JointType.ShoulderCenter, JointType.ShoulderRight, JointType.ElbowRight, JointType.WristRight, JointType.HandRight }, depthFrame, canvas));
canvas.Children.Add(GetBodySegment(joints, brush, new JointType[] { JointType.HipCenter, JointType.HipLeft, JointType.KneeLeft, JointType.AnkleLeft, JointType.FootLeft }, depthFrame, canvas));
canvas.Children.Add(GetBodySegment(joints, brush, new JointType[] { JointType.HipCenter, JointType.HipRight, JointType.KneeRight, JointType.AnkleRight, JointType.FootRight }, depthFrame, canvas));
depthFrame.Dispose();
frame++;
}
Point GetDisplayPosition(Joint joint, DepthImageFrame depthFrame, Canvas skeleton)
{
float depthX, depthY;
KinectSensor sensor = KinectSensor.KinectSensors[0];
DepthImageFormat depthImageFormat = sensor.DepthStream.Format;
DepthImagePoint depthPoint = sensor.CoordinateMapper.MapSkeletonPointToDepthPoint(joint.Position, depthImageFormat);
depthX = depthPoint.X;
depthY = depthPoint.Y;
depthX = Math.Max(0, Math.Min(depthX * 320, 320));
depthY = Math.Max(0, Math.Min(depthY * 240, 240));
int colorX, colorY;
ColorImagePoint colorPoint = sensor.CoordinateMapper.MapDepthPointToColorPoint(depthImageFormat, depthPoint, ColorImageFormat.RgbResolution640x480Fps30);
colorX = colorPoint.X;
colorY = colorPoint.Y;
return new System.Windows.Point((int)(skeleton.Width * colorX / 640.0), (int)(skeleton.Height * colorY / 480));
}
Polyline GetBodySegment(Joint[] joints, Brush brush, JointType[] ids, DepthImageFrame depthFrame, Canvas canvas)
{
PointCollection points = new PointCollection(ids.Length);
for (int i = 0; i < ids.Length; ++i)
{
points.Add(GetDisplayPosition(joints[i], depthFrame, canvas));
}
Polyline polyline = new Polyline();
polyline.Points = points;
polyline.Stroke = brush;
polyline.StrokeThickness = 5;
return polyline;
}
当然,这只适用于wpf。您只需要更改使用代码:
DepthImageFrame depthFrame = e.OpenDepthImageFrame();
canvas.Children.Add(GetBodySegment(joints, brush, new JointType[] { JointType.HipCenter, JointType.Spine, JointType.ShoulderCenter, JointType.Head }, depthFrame, canvas));
canvas.Children.Add(GetBodySegment(joints, brush, new JointType[] { JointType.ShoulderCenter, JointType.ShoulderLeft, JointType.ElbowLeft, JointType.WristLeft, JointType.HandLeft }, depthFrame, canvas));
canvas.Children.Add(GetBodySegment(joints, brush, new JointType[] { JointType.ShoulderCenter, JointType.ShoulderRight, JointType.ElbowRight, JointType.WristRight, JointType.HandRight }, depthFrame, canvas));
canvas.Children.Add(GetBodySegment(joints, brush, new JointType[] { JointType.HipCenter, JointType.HipLeft, JointType.KneeLeft, JointType.AnkleLeft, JointType.FootLeft }, depthFrame, canvas));
canvas.Children.Add(GetBodySegment(joints, brush, new JointType[] { JointType.HipCenter, JointType.HipRight, JointType.KneeRight, JointType.AnkleRight, JointType.FootRight }, depthFrame, canvas));
depthFrame.Dispose();
对于 avateering 示例如何为模型设置动画,您甚至可以创建一个新的 Skeleton
并将 joints
复制到 Skeleton.Joints
,然后只需将该骨架作为“检测到的”骨架传递。请注意,您需要更改此示例中使用的函数所需的任何其他所需变量。我对示例不熟悉,所以我不能给出具体的方法名称,但您可以将全局 Skeleton
替换为您在开始时创建的那个并更新每一帧。所以我会推荐这个:
//in the game class (AvateeringXNA.cs)
StreamReader reader = new StreamReader(@path);
int frame = -1;
JointCollection joints;
Skeleton recorded = new Skeleton();
...
string[] lines = reader.ReadAllLines();
...
void Update(...)
{
string[] coords = lines[frame].Split('@')[1].Split(',');
int jointIndex = 0;
for (int i = 0; i < coords.Length; i += 3)
{
joints[jointIndex].Position.X = int.Parse(coords[i]);
joints[jointIndex].Position.Y = int.Parse(coords[i + 1]);
joints[jointIndex].Position.X = int.Parse(coords[i + 2]);
jointIndex++;
}
recorded.Joints = joints;
...
//preform necessary methods, except with recorded skeleton instead of detected, I think it is:
this.animator.CopySkeleton(recorded);
this.animator.FloorClipPlane = skeletonFrame.FloorClipPlane;
// Reset the filters if the skeleton was not seen before now
if (this.skeletonDetected == false)
{
this.animator.Reset();
}
this.skeletonDetected = true;
this.animator.SkeletonVisible = true;
...
frame++;
}
编辑
当您读取初始地板裁剪平面 (clipPlanes[0]
) 时,它将获得直到第一个空间的整个帧信息。请参阅下文以了解它将如何拆分以及我将如何阅读它:
var newFloorClipPlane = Tuple.Create(Single.Parse(clipPlanes[2]), Single.Parse(clipPlanes[3]), Single.Parse(clipPlanes[4]), Single.Parse(clipPlanes[5]));
以下是您如何布置框架:
frame# timestam@joint1Posx,joint1posy,joint1posz,...jointNPosx,jointNposy,jointNposz floorX floorY floorZ floorW
这里是 `.Split(' ') 生成的数组
["frame#", "timestam@joint1Posx,joint1posy,joint1posz,...jointNPosx,jointNposy,jointNposz", "floorX", "floorY", "floorZ", "floorW"]
因此,示例输入为:
00000002 10112@10,10,10... 11 12 13 14
使用您的代码您将获得:
[2, 10112101010..., 11, 12]
使用我的代码中更正的索引:
[11, 12, 13, 14]
将这一行非常快速地放入控制台应用程序并查看它的输出:
Console.WriteLine(Convert.ToSingle("10,10"));
输出为 1010
对于您要实现的目标,这会创建错误的地板剪裁平面。您需要针对您要实现的目标使用适当的索引。
注意:我将 Convert.ToSingle
更改为 Single.Parse
因为这是更好的做法并且在堆栈跟踪中它们都执行相同的函数
关于c#-4.0 - 如何在Kinect SDK V1.7 (Avateering XNA) 中捕捉运动数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21796703/
如何知道 WM_DEVICECHANGE 的到来? WndProc 被覆盖。我收到了所有消息,但没有一条是 WM_DEVICECHANGE 类型的。 RegisterDeviceNotificatio
我想创建一个滚动的表面列表框,它会在拖动完成后自动捕捉到一个位置,以便屏幕上的中心项目在视口(viewport)中居中。 我已经得到了中心项,但现在像往常一样,WPF 处理大小、屏幕位置和偏移量的方式
如果我有一个使用步长的范围 slider ,例如从 0 到 100,步长为 5,然后我在该范围之间有一个随机值,比如说 56,我如何确定最接近的捕捉值 (55) 是多少? 我正在考虑向前和向后循环,直
我想添加到模块记录器中的所有功能。我想记录函数的“开始”时间和“结束”时间。这样我就可以获得每个函数(同步函数)的执行时间。 但我不知道如何让它工作.. =(我不想以某种动态方式重写函数 - 我想在将
我正在编写一个 C# 应用程序,如果文件已被某个进程使用,我必须在其中显示一条消息,如果该文件不存在,则应用程序需要显示另一条消息。 像这样: try { //Code to open a f
所以我正在使用城市词典 api,他们的术语可以链接到其他使用 [term] 和 api 的框,我想使它们实际上在 markdown 中超链接,即 term所以我尝试制作一个替换正则表达式来做到这一点我
我有一个使用鼠标滚轮 jQuery 插件的水平滚动网站。滚动有效,但我想将每个“文章”捕捉到文档的左侧,这样一旦停止滚动,它就不会停留在一半的位置。 我目前的标记: CSS #viewport { w
我需要在 windows 上录制声音。我需要写信来传输我从演讲者那里听到的内容。我可以依赖什么方法/API? 最佳答案 您可以使用 DirectSound ;可以找到 sample here这是针对麦
for ii = 1:2:2*de.nP G=[one, aux3(:,ii), aux3(:,ii) - aux2(:,ii),aux3(:,ii+1) - a
您好,感谢阅读。我是编程、C# 和套接字编程方面的新手。在我的代码中,我尝试发现问题以在我的应用程序中提供容错能力。以下内容: catch (ArgumentNullException
我有一个函数可以运行用户生成的正则表达式。但是,如果用户输入了一个不会运行的正则表达式,那么它就会停止并跌倒。我试过将行包装在 Try/Catch block 中,但是没有任何反应。 如果有帮助,我正
嵌套的 Try/Catch 是否表示您的编码不干净?我想知道,因为在我的 catch 中,我正在调用另一个方法,如果失败,我会收到另一个运行时错误,所以我很想再次使用另一个 try/catch 将这些
我不知道如何放置一个相对于其同级路径边界框的路径。想象一个像窗口一样的盒子,我想在它的右上角放一个关闭按钮。这是在变换窗口(缩放 3 倍)后组合在一起的框和关闭按钮: 我只是在
我正在尝试使用 UISlider 实现某种形式的捕捉或步骤。我编写了以下代码,但它并没有像我希望的那样顺利。它可以工作,但是当我向上滑动它时,它会向右移动 5 个点,使手指不在“滑动圆”的中心 这是我
目前,我使用 Snap SVG 创建一个小型建模工具。 var p = Snap.path(pathString).attr({fill:'none', stroke:'black', strokeW
我希望能够使用 Snap SVG 将一组集合作为一个组进行拖动。到目前为止,我只能将子集(矩形和文本框)作为一个项目进行拖动,但我想要实现的是集体“表格”是可拖动的,而其中的字段仍保留为单独的形状,因
我有一段代码可以像这样抛出和捕获错误 try { } catch (e: FooException) { } catch (e: BarException) { } finally { } 并且有一些
我定义了一个自定义错误处理程序,它捕获所有异常并将它们保存到日志中。现在,如果我在 mysqli 查询中出现语法错误,例如拼写错误,页面会在此时完全停止加载。不会引发异常,因此不会触发错误处理程序,也
我有以下分组的svg文件,g的id为flower-petals,然后里面的每个部分都是花瓣,我似乎无法更改每个内部路径的填充。 我将 snap 的 petals 变量定义为 petals.Snap("
当脚本执行 Read-Host cmdlet,关闭窗口不会激活 finally堵塞。下面是一个随意但功能最少的示例。我正在使用 PowerShell 5.0。 Beep() 只是为了让 finally
我是一名优秀的程序员,十分优秀!