c# - 使用 Kinect 缩放图像不平滑 - 进近时需要更正

标签 c# wpf kinect

我正在尝试使用 Kinect 获得放大/缩小效果。基本思想是:

  1. 检测双手是否举起bool lefthand, righthand;
  2. 计算双手之间的距离prevDistance
  3. 在捕获的下一帧中,如果手之间的距离小于prevDistance,则ZoomOut else ZoomIn

这对我有用,但这种方法不会导致非常平滑的放大/缩小。

    bool lefthand=false, righthand=false;
    float prevDistance=0;

//Inside SkeletonFrameReady event

if(lefthand && righthand && prevDistance=0)
{
prevDistance = skeleton.Joints[JointID.HandRight].Postion.X - skeleton.Joints[JointID.HandLeft].Position.X;
}
if(lefthand && righthand)
{
ZoomingFunction(skeleton.Joints[JointID.HandRight].Postion.X, skeleton.Joints[JointID.HandLeft].Position.X, prevDistance);
}
if(!lefthand && !righthand)
{
prevDistance =0;
}

缩放功能:

private void ZoomingFunction(double RPostion, LPosition, double curDistance)
{
//0.3 has been added to get kind of integral points to zoom, else the zooming occurs very fast to control
    if(RPosition - LPosition < curDistance - 0.3F)
    {
//Zoom out
    img.Width -=20;
    }
    if(RPosition - LPosition > curDistance + 0.3F)
    {
//Zoom in
    img.Width +=20;
    }
}

这种方法在我看来不是很优雅。我试图获得一些平滑的缩放效果,就像在这个 Worldwide Telescope 的 Kinect 演示中一样。链接:http://www.youtube.com/watch?v=1-tMp4WkQjA

有什么改进的建议吗?

最佳答案

我认为这里有 2 个可能的问题需要解决。

第一个是误差累积。当在每一帧上,您从 SD 获得手的位置 + 一点错误(或噪音)时,就会发生这种情况。我对此的解决方案是:

  1. 当您检测到用户抬起手并准备开始缩放时,存储手之间的距离和当时的缩放级别(我们称它们为 startDistance 和 startZoom)

  2. 每一帧,根据原始值、原始手距和新距离计算新的缩放级别。 你可以这样做:


float newWidth = startWidth * currentDistance / startDistance;
float newHeight = startHeight * currentDistance / startDistance;

这应该最大限度地减少任何错误累积。

第二个问题是提高缩放的平滑度并消除您可能从 SDK 获得的任何噪音。这很简单。您可以尝试在当前帧和上一帧之间插入手部距离值。如果需要,如果您确实得到了嘈杂的值,您可以尝试跨更多帧进行插值。

你可以这样做:


float interpolatedDistance = (currentDistance + prevDistance) / 2;
float newWidth = startWidth * interpolatedDistance / startDistance;
float newHeight = startHeight * InterpolatedDistance / startDistance;
prevDistance = currentDistance;

currentDistance 是这一帧手的距离,prevDistance 是上一帧手的距离。

告诉我们这是否有帮助

关于c# - 使用 Kinect 缩放图像不平滑 - 进近时需要更正,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9051868/

相关文章:

c# - 什么是NullReferenceException,如何解决?

c# - 推特状态更新 : set source (C#)

c# - ASP MVC 和 postgres

c# - 使用 Kinect 查找肘部角度

c# - 仅检测来自 Kinect 正前方用户的语音

c# - 设置两个kinect : v1 and v2

c# - 提供商模型和性能

c# - Open/SaveFileDialog 类之间的区别及其在 WPF 窗体中的使用

c# - WPF RichTextBox 内存泄漏

c# - ListBox selectedItem 开始工作但设置在 MVVM 中不起作用