我正在尝试使用 Kinect 获得放大/缩小效果。基本思想是:
- 检测双手是否举起
bool lefthand, righthand;
- 计算双手之间的距离
prevDistance
- 在捕获的下一帧中,如果手之间的距离小于
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 获得手的位置 + 一点错误(或噪音)时,就会发生这种情况。我对此的解决方案是:
当您检测到用户抬起手并准备开始缩放时,存储手之间的距离和当时的缩放级别(我们称它们为
startDistance 和 startZoom
)每一帧,根据原始值、原始手距和新距离计算新的缩放级别。 你可以这样做:
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/