Kinect V2 - 存储点位置时的重复值

时间:2018-05-14 18:32:17

标签: c# multithreading kinect kinect-v2

这是我用来记录包含一些计算的点的代码。所以,我得到了点的值位置,做了一些数学运算,然后将它们保存到列表中。

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相比那些重复一次我得到二十分0.05513然后接下来是二十分之0.05013。

EDIT 以下是我将多个值存储到列表中时获得的示例值。

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);
                }
            }
        }
    }

0 个答案:

没有答案