这是我用来记录包含一些计算的点的代码。所以是的,我得到了点的值位置,做一些数学运算,然后将它们保存到一个列表中。
gesture.L.E.AddFrameDescriptor(
joints[JointType.ElbowLeft].Position.X, joints[JointType.ElbowLeft].Position.Y, joints[JointType.ElbowLeft].Position.Z,
joints[JointType.SpineMid].Position.X, joints[JointType.SpineMid].Position.Y, joints[JointType.SpineMid].Position.Z,
spineBaseShoulderRHO
);
gesture.L.W.AddFrameDescriptor(
joints[JointType.WristLeft].Position.X, joints[JointType.WristLeft].Position.Y, joints[JointType.WristLeft].Position.Z,
joints[JointType.SpineMid].Position.X, joints[JointType.SpineMid].Position.Y, joints[JointType.SpineMid].Position.Z,
spineBaseShoulderRHO
);
gesture.L.H.AddFrameDescriptor(
joints[JointType.HandTipLeft].Position.X, joints[JointType.HandTipLeft].Position.Y, joints[JointType.HandTipLeft].Position.Z,
joints[JointType.SpineMid].Position.X, joints[JointType.SpineMid].Position.Y, joints[JointType.SpineMid].Position.Z,
spineBaseShoulderRHO
);
gesture.R.E.AddFrameDescriptor(
joints[JointType.ElbowRight].Position.X, joints[JointType.ElbowRight].Position.Y, joints[JointType.ElbowRight].Position.Z,
joints[JointType.SpineMid].Position.X, joints[JointType.SpineMid].Position.Y, joints[JointType.SpineMid].Position.Z,
spineBaseShoulderRHO
);
gesture.R.W.AddFrameDescriptor(
joints[JointType.WristRight].Position.X, joints[JointType.WristRight].Position.Y, joints[JointType.WristRight].Position.Z,
joints[JointType.SpineMid].Position.X, joints[JointType.SpineMid].Position.Y, joints[JointType.SpineMid].Position.Z,
spineBaseShoulderRHO
);
gesture.R.H.AddFrameDescriptor(
joints[JointType.HandTipRight].Position.X, joints[JointType.HandTipRight].Position.Y, joints[JointType.HandTipRight].Position.Z,
joints[JointType.SpineMid].Position.X, joints[JointType.SpineMid].Position.Y, joints[JointType.SpineMid].Position.Z,
spineBaseShoulderRHO
);
出于某种原因,我得到了很多重复的值,重复了 20 次。我注意到如果我只保存一个值,我会得到重要的值并且没有更多的重复,加上值的差异更接近于彼此,比如 0.05513 然后 0.05413 与那些重复的值相比,一旦我得到 20 个 0.05513 然后下一个是 20 0.05013。
编辑如果我将多个值存储到列表中,这是我得到的示例值。
0.399695181 0.399695181 0.399695181 0.399695181 0.399695181 0.399695181 0.399695181 0.399695181 0.399695181 0.399695181 0.399695181 0.399695181 0.399695181 0.399695181 0.399695181 0.399695181 0.399695181 0.399695181 0.399695181 0.399695181 0.399695181 0.401078759 0.401078759 0.401078759 0.401078759 0.401078759 0.401078759 0.401078759 0.401078759 0.401078759 0.401078759 0.401078759 0.401078759 0.401078759 0.401078759 0.401078759 0.401078759 0.401078759 0.401078759 0.401078759 0.401078759 0.401423597 0.401423597 0.401423597 0.401423597 0.401423597 0.401423597 0.401423597 0.401423597 0.401423597 0.401423597 0.401423597 0.401423597 0.401423597 0.401423597 0.401423597 0.401423597 0.401423597 0.401423597 0.401423597 0.401423597 0.401669625 0.401669625 0.401669625 0.401669625 0.401669625 0.401669625 0.401669625 0.401669625 0.401669625 0.401669625 0.401669625 0.401669625 0.401669625 0.401669625 0.401669625 0.401669625 0.401669625 0.401669625 0.401669625 0.401669625
如您所见,这些数字重复了二十次。
扩展代码
private void DrawBody(IReadOnlyDictionary<JointType, Joint> joints, IDictionary<JointType, Point> jointPoints, DrawingContext drawingContext, Pen drawingPen)
{
foreach (var bone in this.bones)
{
this.DrawBone(joints, jointPoints, bone.Item1, bone.Item2, drawingContext, drawingPen);
}
foreach (JointType jointType in joints.Keys)
{
if (!(jointType.Equals(JointType.HandLeft) || jointType.Equals(JointType.HandRight) || jointType.Equals(JointType.ThumbLeft) || jointType.Equals(JointType.ThumbRight)))
{
Brush drawBrush = null;
TrackingState trackingState = joints[jointType].TrackingState;
if (trackingState == TrackingState.Tracked)
{
drawBrush = this.trackedJointBrush;
check.Add(joints[JointType.ElbowLeft].Position.X);
if (this.status_active)
{
if (!this.status_ready && (new MathFunctions().GetDist2P(joints[JointType.HandTipLeft].Position.X, joints[JointType.HandTipRight].Position.X) <= 0.03 && joints[JointType.HandTipLeft].Position.Y < joints[JointType.SpineMid].Position.Y && joints[JointType.HandTipRight].Position.Y < joints[JointType.SpineMid].Position.Y))
{
lbl_status.Content = "READY"; lbl_status.Foreground = Brushes.Green; ellps_status.Fill = Brushes.Green;
this.status_ready = true;
}
else if (this.status_ready)
{
if (!this.status_recording && (joints[JointType.HandTipLeft].Position.Y > joints[JointType.SpineBase].Position.Y || joints[JointType.HandTipRight].Position.Y > joints[JointType.SpineBase].Position.Y))
{
lbl_status.Content = "RECORDING"; lbl_status.Foreground = Brushes.Red; ellps_status.Fill = Brushes.Red;
this.status_recording = true;
this.gesture = new Gesture();
spineBaseShoulderRHO = new MathFunctions().GetRho(
new MathFunctions().GetDist2P(joints[JointType.SpineBase].Position.X, joints[JointType.SpineShoulder].Position.X),
new MathFunctions().GetDist2P(joints[JointType.SpineBase].Position.Y, joints[JointType.SpineShoulder].Position.Y),
new MathFunctions().GetDist2P(joints[JointType.SpineBase].Position.Z, joints[JointType.SpineShoulder].Position.Z)
);
}
else if (status_recording)
{
if (joints[JointType.HandTipLeft].Position.Y < joints[JointType.SpineBase].Position.Y && joints[JointType.HandTipRight].Position.Y < joints[JointType.SpineBase].Position.Y)
{
lbl_status.Content = "ACTIVE"; lbl_status.Foreground = Brushes.Black; ellps_status.Fill = Brushes.Black;
this.status_active = true;
this.status_ready = false;
this.status_recording = false;
gesture = new SLFunctions().RemoveRedundantPoints(gesture);
// identify gesture
if (tbox_word.Text == "")
{
SimilarityIndex minIndex = new SLFunctions().IdentifyGesture(library, gesture);
lbl_word.Content = minIndex.gestureName;
}
// new gesture
else
{
gesture.name = tbox_word.Text;
new SLFunctions().SaveGesture(gesture, "library");
library.Add(gesture);
tbox_word.Text = "";
}
}
#region AddFrameDescriptor
gesture.L.E.AddFrameDescriptor(
joints[JointType.ElbowLeft].Position.X, joints[JointType.ElbowLeft].Position.Y, joints[JointType.ElbowLeft].Position.Z,
joints[JointType.SpineMid].Position.X, joints[JointType.SpineMid].Position.Y, joints[JointType.SpineMid].Position.Z,
spineBaseShoulderRHO
);
gesture.L.W.AddFrameDescriptor(
joints[JointType.WristLeft].Position.X, joints[JointType.WristLeft].Position.Y, joints[JointType.WristLeft].Position.Z,
joints[JointType.SpineMid].Position.X, joints[JointType.SpineMid].Position.Y, joints[JointType.SpineMid].Position.Z,
spineBaseShoulderRHO
);
gesture.L.H.AddFrameDescriptor(
joints[JointType.HandTipLeft].Position.X, joints[JointType.HandTipLeft].Position.Y, joints[JointType.HandTipLeft].Position.Z,
joints[JointType.SpineMid].Position.X, joints[JointType.SpineMid].Position.Y, joints[JointType.SpineMid].Position.Z,
spineBaseShoulderRHO
);
gesture.R.E.AddFrameDescriptor(
joints[JointType.ElbowRight].Position.X, joints[JointType.ElbowRight].Position.Y, joints[JointType.ElbowRight].Position.Z,
joints[JointType.SpineMid].Position.X, joints[JointType.SpineMid].Position.Y, joints[JointType.SpineMid].Position.Z,
spineBaseShoulderRHO
);
gesture.R.W.AddFrameDescriptor(
joints[JointType.WristRight].Position.X, joints[JointType.WristRight].Position.Y, joints[JointType.WristRight].Position.Z,
joints[JointType.SpineMid].Position.X, joints[JointType.SpineMid].Position.Y, joints[JointType.SpineMid].Position.Z,
spineBaseShoulderRHO
);
gesture.R.H.AddFrameDescriptor(
joints[JointType.HandTipRight].Position.X, joints[JointType.HandTipRight].Position.Y, joints[JointType.HandTipRight].Position.Z,
joints[JointType.SpineMid].Position.X, joints[JointType.SpineMid].Position.Y, joints[JointType.SpineMid].Position.Z,
spineBaseShoulderRHO
);
#endregion
}
}
}
}
else if (trackingState == TrackingState.Inferred)
{
drawBrush = this.inferredJointBrush;
}
if (drawBrush != null)
{
drawingContext.DrawEllipse(drawBrush, null, jointPoints[jointType], JointThickness, JointThickness);
}
}
}
}