2012-11-09 28 views
2

我使用Kinect的SDK 1.6,我正在關注的骨架跟蹤Funamentals教程可用here的Windows Kinect的快速入門系列的。Kinect的SDK 1.6和Joint.ScaleTo方法

即使這些教程已針對SDK 1.0製作,一切都做得較好,直到我按照說明我的手的位置地圖上的自定義大小的窗口(比如1280×720)

丹·費爾南德斯是使用下面一行代碼來實現這一

private void ScalePosition(FrameworkElement element, Joint joint) 
    { 
     // Convert the value to X/Y; 
     Joint scaledJoint = joint.ScaleTo(1280, 720); 

     .... 
    }  

好,方法ScaleTo不是,它應該在Kinect的SDK中提供的自定義功能,但根據我的編輯,有沒有這樣的方法。我找不到它,我認爲它可能已被移動/重命名/無論自SDK 1.0以來。

只是爲了確保一切正常,這是我using名單,everyithing其他(骨架跟蹤等)的工作,所以我真的不能弄清楚

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.Windows; 
using System.Windows.Controls; 
using System.Windows.Data; 
using System.Windows.Documents; 
using System.Windows.Input; 
using System.Windows.Media; 
using System.Windows.Media.Imaging; 
using System.Windows.Navigation; 
using System.Windows.Shapes; 

using Microsoft.Kinect; 
using Microsoft.Kinect.Toolkit; 
using Microsoft.Samples.Kinect.WpfViewers; 

我可以進一步給應要求提供有關我的代碼的詳細信

回答

8

如果你有正確的參考Coding4Fun,你實際上只是缺少這樣的:

using Coding4Fun.Kinect.Wpf; 

在您的代碼的開頭。

2

縮放是這裏的Coding4Fun庫的一部分,可供選擇: http://c4fkinect.codeplex.com/

或者,您也可以編寫自己的縮放。

像這樣的東西會創建一個右手的追蹤「中心框」,以右肩爲中心,並將其縮放到主屏幕的分辨率。

double xScaled = (rightHand.Position.X - leftShoulder.Position.X)/((rightShoulder.Position.X - leftShoulder.Position.X) * 2) * SystemParameters.PrimaryScreenWidth; 
double yScaled = (rightHand.Position.Y - head.Position.Y)/(rightHip.Position.Y - head.Position.Y) * SystemParameters.PrimaryScreenHeight; 

下面是縮放Kinect的座標,屏幕分辨率功能的另一個例子:

private static double ScaleY(Joint joint) 
{ 
    double y = ((SystemParameters.PrimaryScreenHeight/0.4) * -joint.Position.Y) + (SystemParameters.PrimaryScreenHeight/2); 
    return y; 
} 

private static void ScaleXY(Joint shoulderCenter, bool rightHand, Joint joint, out int scaledX, out int scaledY) 
{ 
    double screenWidth = SystemParameters.PrimaryScreenWidth; 

    double x = 0; 
    double y = ScaleY(joint); 

    // if rightHand then place shouldCenter on left of screen 
    // else place shouldCenter on right of screen 
    if (rightHand) 
    { 
     x = (joint.Position.X - shoulderCenter.Position.X) * screenWidth * 2; 
    } 
    else 
    { 
     x = screenWidth - ((shoulderCenter.Position.X - joint.Position.X) * (screenWidth * 2)); 
    } 


    if (x < 0) 
    { 
     x = 0; 
    } 
    else if (x > screenWidth - 5) 
    { 
     x = screenWidth - 5; 
    } 

    if (y < 0) 
    { 
     y = 0; 
    } 

    scaledX = (int)x; 
    scaledY = (int)y; 
} 
+2

謝謝,但我已經下載了Coding4Fun庫和添加引用(WPF相關的一個),但它確實不工作.. – INElutTabile

+0

你上面的'使用'代碼塊不包括對它的引用。你忘了添加它作爲參考或衝入「使用」部分? –

0
you can fix the error using this dll file 


http://c4fkinect.codeplex.com/releases/view/76271