【问题标题】:Tracking speed with kinect and Visual Studio使用 kinect 和 Visual Studio 跟踪速度
【发布时间】:2015-03-08 04:50:58
【问题描述】:

我需要跟踪踢球的速度。我编写了这段代码,但是当我运行程序时,即使我的右脚移动得非常快,速度也没有太大变化。
怎么了? 有不同的方法吗?

if (bandera == true)
{
X1 = skeleton.Joints[JointType.FootRight].Position.X;
Y1 = skeleton.Joints[JointType.FootRight].Position.Y;
Z1 = skeleton.Joints[JointType.FootRight].Position.Z;
}
if (bandera == false)
{  
X2 = skeleton.Joints[JointType.FootRight].Position.X;
Y2 = skeleton.Joints[JointType.FootRight].Position.Y;
Z2 = skeleton.Joints[JointType.FootRight].Position.Z;
}
bandera = !bandera;

float d= (((X1 - X2) * (X1 - X2)) + ((Y1 - Y2) * (Y1 - Y2)) + ((Z1 - Z2 * (Z1 - Z2))));
double distance = System.Math.Sqrt(d);
double speed= 30 * distance;
Console.WriteLine(speed);

如你所知:速度=距离/时间 我知道每秒有 30 FPS,所以时间 = 1/30 所以速度等于距离除以 (1/30) 等于 30 * 距离

【问题讨论】:

标签: c# visual-studio kinect


【解决方案1】:

嗯...因为您使用相同的点...所以当您减去时,它都是 0...

X1 = skeleton.Joints[JointType.FootRight].Position.X;
...
X2 = skeleton.Joints[JointType.FootRight].Position.X;
...

同一点,x1=x2x1-x2=0,然后一切都变成梨形......


根据您的更新:

  1. 我希望这是一个循环,否则,你的旗帜 (bandera) 不会有太大作用。我希望你也意识到第一次循环时,你的一些XY 不会被初始化(因为它只会通过其中一种情况)。

  2. 现在,d=t*s,所以您的距离计算完全正确。

如果您在初始化变量和计算后丢弃一些调试输出,您会得到什么?

【讨论】:

  • 这段代码在 Kinect 的帧事件上运行(我假设),正如她所说,它每秒运行 30 次。因此,每隔一帧,X1 和 X2 都会更新为不同的值。
【解决方案2】:

你搞砸了距离公式。放置育儿时要非常小心。应该是这样的

float d = (X1 - X2) * (X1 - X2) + (Y1 - Y2) * (Y1 - Y2) + (Z1 - Z2) * (Z1 - Z2);

也不需要将布尔值与true 进行比较。您还可以将距离计算移到自己的方法中,以使事情更清楚,避免需要时间才能发现的错误。我建议是这样的:

double distance(Joint a, Joint b)
{
    float d2 = (b.X - a.X) * (b.X - a.X) + (b.Y - a.Y) * (b.Y - a.Y) + (b.Z - a.Z) * (b.Z - a.Z);
    return System.Math.Sqrt(d2)
}

...

if (bandera)
{
    a = skeleton.Joints[JointType.FootRight];
}
else
{  
    b = skeleton.Joints[JointType.FootRight];
}
bandera = !bandera;

double speed = 30 * distance(a, b);
Console.WriteLine(speed);

您的速度计算很容易出现波动,因此平均超过 10 帧可能也会有所帮助。

【讨论】:

    【解决方案3】:

    我在您的代码中看到的唯一错误是您在距离计算中缺少括号: (Z1 - Z2) 必须在括号之间,否则操作顺序不正确。其他一切都应该正常工作。正如 vidstige 所说,当踢球进行时速度会有所不同,所以为了你所说的目的,我建议保持最大的价值。

    致敬!!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多