2016-04-12 3 views
0

Я пытаюсь присвоить имя каждому суставу. Функция призвание:Kinect: Назначить суставное имя для соединения

for(int t=0;t<body._body.Length;t++) 
     { 
      DrawPoint(body._body[t], canvs,col_t,col_i); 
     } 

и полная функция DrawPoint:

public static void DrawPoint(JointData _joint, Canvas canvs, Color col_t, Color col_i) 
    { 

     #region convert JointData to Kinect.Joint type 
     Joint currentJoint; 
     currentJoint.TrackingState = JointTrackingState.NotTracked; 
     currentJoint.Position.X = -1; 
     currentJoint.Position.Y = -1; 
     currentJoint.Position.Z = -1; 
     currentJoint.JointType = JointType.AnkleLeft; 

     if (_joint._TrackState == "Tracked") 
      currentJoint.TrackingState = JointTrackingState.Tracked; 
     if (_joint._TrackState == "Inferred") 
      currentJoint.TrackingState = JointTrackingState.Inferred; 
     if (_joint._TrackState == "NotTracked") 
      currentJoint.TrackingState = JointTrackingState.NotTracked; 

     if (_joint._jointType == "AnkleLeft") 
      currentJoint.JointType = JointType.AnkleLeft; 
     if (_joint._jointType == "AnkleRight") 
      currentJoint.JointType = JointType.AnkleRight; 
     if (_joint._jointType == "ElbowLeft") 
      currentJoint.JointType = JointType.ElbowLeft; 
     if (_joint._jointType == "ElbowRight") 
      currentJoint.JointType = JointType.ElbowRight; 
     if (_joint._jointType == "FootLeft") 
      currentJoint.JointType = JointType.FootLeft; 
     if (_joint._jointType == "FootRight") 
      currentJoint.JointType = JointType.FootRight; 
     if (_joint._jointType == "HandLeft") 
      currentJoint.JointType = JointType.HandLeft; 
     if (_joint._jointType == "HandRight") 
      currentJoint.JointType = JointType.HandRight; 
     if (_joint._jointType == "HandTipLeft") 
      currentJoint.JointType = JointType.HandTipLeft; 
     if (_joint._jointType == "HandTipRight") 
      currentJoint.JointType = JointType.HandTipRight; 
     if (_joint._jointType == "Head") 
      currentJoint.JointType = JointType.Head; 
     if (_joint._jointType == "HipLeft") 
      currentJoint.JointType = JointType.HipLeft; 
     if (_joint._jointType == "HipRight") 
      currentJoint.JointType = JointType.HipRight; 
     if (_joint._jointType == "KneeLeft") 
      currentJoint.JointType = JointType.KneeLeft; 
     if (_joint._jointType == "KneeRight") 
      currentJoint.JointType = JointType.KneeRight; 
     if (_joint._jointType == "Neck") 
      currentJoint.JointType = JointType.Neck; 
     if (_joint._jointType == "ShoulderLeft") 
      currentJoint.JointType = JointType.ShoulderLeft; 
     if (_joint._jointType == "ShoulderRight") 
      currentJoint.JointType = JointType.ShoulderRight; 
     if (_joint._jointType == "SpineBase") 
      currentJoint.JointType = JointType.SpineBase; 
     if (_joint._jointType == "SpineMid") 
      currentJoint.JointType = JointType.SpineMid; 
     if (_joint._jointType == "SpineShoulder") 
      currentJoint.JointType = JointType.SpineShoulder; 
     if (_joint._jointType == "ThumbLeft") 
      currentJoint.JointType = JointType.ThumbLeft; 
     if (_joint._jointType == "ThumbRight") 
      currentJoint.JointType = JointType.ThumbRight; 
     if (_joint._jointType == "WristLeft") 
      currentJoint.JointType = JointType.WristLeft; 
     if (_joint._jointType == "WristRight") 
      currentJoint.JointType = JointType.WristRight; 

     currentJoint.Position.X = (float)Convert.ToDouble(_joint._position[0]); 
     currentJoint.Position.Y = (float)Convert.ToDouble(_joint._position[1]); 
     currentJoint.Position.Z = (float)Convert.ToDouble(_joint._position[2]); 
     #endregion 

     #region drawing 

     Color currentColor = Colors.Blue; 

     if (currentJoint.TrackingState == TrackingState.NotTracked) return; 

     //if (currentJoint.TrackingState == TrackingState.Inferred) currentColor = Colors.Yellow; 
     if (currentJoint.TrackingState == TrackingState.Inferred) currentColor = col_i; 
     //if (currentJoint.TrackingState == TrackingState.Tracked) currentColor = Colors.Green; 
     if (currentJoint.TrackingState == TrackingState.Tracked) currentColor = col_t; 

     currentJoint = ScaleTo(currentJoint, canvs.ActualWidth, canvs.ActualHeight); 

     Ellipse ellipse = new Ellipse 
     { 
      Width = 8, 
      Height = 8, 
      Fill = new SolidColorBrush(currentColor) 
     }; 

     Canvas.SetLeft(ellipse, currentJoint.Position.X - ellipse.Width/2); 
     Canvas.SetTop(ellipse, currentJoint.Position.Y - ellipse.Height/2); 

     canvs.Children.Add(ellipse); 
     #endregion 

    } 

Однако я получаю ошибку на линии

currentJoint.TrackingState = JointTrackingState.NotTracked; 

, что "Использование неназначенную локальной переменной«currentJoint '" и затем сделать currentJoint.Position и currentJoint.JointType ошибки возврата« Невозможно изменить возвращаемое значение «Joint.Position», потому что это не переменная "и" Свойство или индексатор "Joint.JointType" не могут быть назначены - это только чтение ".

Как я могу исправить эти ошибки? Заранее спасибо!

ответ

0

У вас возникли проблемы? Единственное, что я мог заметить, может быть ошибочным в том, что Joint currentJoint;, возможно, потребуется изменить на Joint currentJoint = new Joint(); Надеюсь, это решит проблему.