我尝试为每个关节指定一个名称。调用函数是:
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 :(得分:0)
你找到了问题吗?我唯一可能看到错误的是Joint currentJoint;
可能需要更改为Joint currentJoint = new Joint();
希望这可以解决问题。