2014-11-21 40 views
0

我正在研究一個kinect項目..我試圖找到偏移量(聯合座標之間的差異)並通過使用TCP/IP的網絡發送它。不過,我對着接近關節的前值的問題.. 這是到目前爲止我的代碼:找到Kinect的偏移(座標之間的差異)

Joint right = skel.Joints[JointType.HandRight]; 
double right = right.Position.X; 


/*   
I need an operation here to calculate the offset of right before sending it 
Meaning, offset= right(current coordinate)-right(previous coordinate) 
How can I do this in C# ? 
I have tried this operation as mentioned below but it is printing all zeros although I moved (if move, previous - current coordinates shall not be zero) 
*/ 

//--------------------------------------------------------------------------- 
double offset = 0; 
double[] of = new double[2]; 

    for (int i = 0; i < of.Length; i++) 
{ 
    if (i > 2) 
    { 
    break; 
    } 
    of[i] = right; 
    offset = of[1] - of[0];         
    } 

//---------------------------------------------------------------------------  

//convert the data to bytes before sending 
byte[] rh = BitConverter.GetBytes(offset); 

//sending the data to the server 
client.Send(rh, rh.Length); 

回答

0
// make it global 

    double previousval=-1000; 
    double currentVal=-1000; 

then in your code 

    Joint right = skel.Joints[JointType.HandRight]; 
    currentVal=right.Position.X; 

    double offset = 0; 
    if(prev==-1000) 
     offset = currentVal - currentVal; 
    else 
     offset = previousval - currentVal; 

    previousval=currentVal; 
+0

感謝bro..in你的代碼,是ü使用偏移=前電流?它應該是當前,以前..如何高潮做最新的前更改?請向我解釋我的代碼是如何工作的,以及我在代碼中做了什麼錯誤? – Thale 2014-11-25 16:13:50

+0

@Thale在i = 0的for循環中,將值存儲在第0個索引處,然後當i = 1時再次存儲該值,那麼您將在第1個索引處存儲相同的值,這就是爲什麼總是得到offset = 0的原因 – 2014-11-26 05:52:49