Пример #1
0
        private void SensorSkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
        {
            Skeleton[] skeletons = new Skeleton[0];

            using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame())
            {
                if (skeletonFrame != null)
                {
                    skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength];
                    skeletonFrame.CopySkeletonDataTo(skeletons);
                }
            }
            using (DrawingContext dc = this.drawingGroup.Open())
            {
                // Draw a transparent background to set the render size
                dc.DrawRectangle(Brushes.Black, null, new Rect(0.0, 0.0, RenderWidth, RenderHeight));

                if (skeletons.Length != 0)
                {
                    foreach (Skeleton skel in skeletons)
                    {
                        RenderClippedEdges(skel, dc);

                        if (skel.TrackingState == SkeletonTrackingState.Tracked)
                        {
                            Joint           joint0     = skel.Joints[JointType.HandRight];
                            DepthImagePoint depthPoint = this.sensor.CoordinateMapper.MapSkeletonPointToDepthPoint(joint0.Position, DepthImageFormat.Resolution640x480Fps30);
                            this.DrawBonesAndJoints(skel, dc);
                            Angles MyAngles    = new Angles();
                            byte[] ReadyAngles = MyAngles.GetVector(skel, depthPoint);


                            //RightElbow.Text = ReadyAngles[0].ToString();
                            //RightShoulder.Text = ReadyAngles[1].ToString();
                            //LeftElbow.Text = ReadyAngles[2].ToString();
                            // LeftShoulder.Text = ReadyAngles[3].ToString();
                            byte[] SequenceStart = { 255 };


                            //SERİ İÇİN AÇ//////////////////////////////////////////////
                            //if (ArduinoPort.IsOpen)
                            //{
                            //    //  ArduinoPort.Write(SequenceStart, 0, 1);
                            //    //  ArduinoPort.Write(ReadyAngles, 0, 4);
                            //    ArduinoPort.Write(ReadyAngles, 0, 4);
                            //    Console.Write("Sağ Dirsek Eklemi: " + RightElbow.Text + "\n");
                            //    Console.Write("Sağ Omuz(Sağ-Sol) Eklemi : " + RightElbow.Text + "\n");
                            //    Console.Write("Sağ Omuz(Yukarı-Aşağı) Eklemi : " + RightElbow.Text + "\n");
                            //    Console.Write("Sol Dirsek Eklemi: " + RightElbow.Text + "\n");
                            //}



                            //String s = ReadyAngles[0].ToString() + "," + ReadyAngles[1].ToString() + "*" + ReadyAngles[2].ToString() + "/";
                            //byte[] byteTime = Encoding.ASCII.GetBytes(s);
                            // ns.Write(byteTime, 0, byteTime.Length);



                            ns.Write(ReadyAngles, 0, ReadyAngles.Length);
                        }
                        else if (skel.TrackingState == SkeletonTrackingState.PositionOnly)
                        {
                            dc.DrawEllipse(
                                this.centerPointBrush,
                                null,
                                this.SkeletonPointToScreen(skel.Position),
                                BodyCenterThickness,
                                BodyCenterThickness);
                        }
                    }
                }
                // prevent drawing outside of our render area
                this.drawingGroup.ClipGeometry = new RectangleGeometry(new Rect(0.0, 0.0, RenderWidth, RenderHeight));
            }
        }
Пример #2
0
        private void SensorSkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
        {
            Skeleton[] skeletons = new Skeleton[0];

            using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame())  {
                if (skeletonFrame != null)
                {
                    skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength];
                    skeletonFrame.CopySkeletonDataTo(skeletons);
                }
            }

            using (DrawingContext dc = this.drawingGroup.Open()) {
                // Draw a transparent background to set the render size
                dc.DrawRectangle(Brushes.Black, null, new Rect(0.0, 0.0, RenderWidth, RenderHeight));

                if (skeletons.Length != 0)
                {
                    contador += 1;
                    if (contador > 59)
                    {
                        contador = 0;
                    }
                    foreach (Skeleton skel in skeletons)
                    {
                        RenderClippedEdges(skel, dc);

                        if (skel.TrackingState == SkeletonTrackingState.Tracked)
                        {
                            Angles MyAngles    = new Angles();
                            byte[] ReadyAngles = MyAngles.GetVector(skel);
                            //statusBarText.Text = "CodoDerecho: " + ReadyAngles[0].ToString() + "   \t\t HombroDerecho: " + ReadyAngles[1].ToString() + "\t\t CodoIzq: " + ReadyAngles[2].ToString() + "\t\t HombroIzq: " + ReadyAngles[3].ToString();



                            //######### Inicio: Fill Aux Angles ###########
                            if (ReadyAngles[0] < 50)
                            {
                                aux[0] = true;
                            }
                            if (ReadyAngles[0] >= 50 && ReadyAngles[0] < 80)
                            {
                                aux[1] = true;
                            }
                            if (ReadyAngles[0] >= 80 && ReadyAngles[0] < 120)
                            {
                                aux[2] = true;
                            }
                            if (ReadyAngles[0] >= 120 && ReadyAngles[0] < 140)
                            {
                                aux[3] = true;
                            }

                            statusBarText.Text = "\t" + aux[0] + " " + aux[1] + " " + aux[2] + " " + aux[3];

                            //######### Fin: Fill Aux Angles ###########
                            this.DrawBonesAndJoints(skel, dc);
                        }
                        else if (skel.TrackingState == SkeletonTrackingState.PositionOnly)
                        {
                            dc.DrawEllipse(
                                this.centerPointBrush,
                                null,
                                this.SkeletonPointToScreen(skel.Position),
                                BodyCenterThickness,
                                BodyCenterThickness);
                        }
                    }
                }

                // prevent drawing outside of our render area
                this.drawingGroup.ClipGeometry = new RectangleGeometry(new Rect(0.0, 0.0, RenderWidth, RenderHeight));
            }
        }