我试图获得放大/缩小效果使用Kinect。其基本思想是:
如果双手都是bool lefthand, righthand;,
prevDistance计算手与手之间的距离
prevDistance,则ZoomOut ZoomOut 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;
}
}在我看来,这种方法不太优雅。我试图获得一些平滑的放大效果,如在这个全球望远镜的Kinect演示。链接:http://www.youtube.com/watch?v=1-tMp4WkQjA
有什么改进的建议吗?
发布于 2012-01-29 20:45:19
我认为这里有两个可能的问题。
第一个是错误积累。这种情况发生在每个帧上,您从SD得到手的位置+一个小错误(或噪音)。我的解决办法是:
当您检测到用户举起手并准备开始缩放时,在此时存储手与缩放级别之间的距离(让我们称它们为startDistance and 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是上一帧中的双手之间的距离。
告诉我们这是否有帮助
发布于 2012-01-29 08:42:23
我可能建议的唯一两件事是在ScaleTransfrom上设置一个调整大小和使用绑定的UIElemnt。唯一的另一件事是我相信。波涛汹涌是因为你在三角洲的高处移动。有更多的if语句,这些语句捕获不同的区域,比如1、4和6。
编辑
您将不得不玩弄这些值,但我会这样做:
double deltaPosition = RPosition - LPosition;
if(deltaPosition < curDistance - 0.3f)
img.Width -= 4;
else if(deltaPosition < curDistance - 0.2f)
img.Width -= 2;
else if(deltaPosition < curDistance - 0.1f)
img.Width -= 1;
else if(deltaPosition > curDistance + 0.3F)
img.Width += 4;
else if(deltaPosition > curDistance + 0.2F)
img.Width += 2;
else if(deltaPosition > curDistance + 0.1F)
img.Width += 1;https://stackoverflow.com/questions/9051868
复制相似问题