Ejemplo n.º 1
0
        // get hand pos
        System.Drawing.Point?GetJoint2DPoint(JointType j, Skeleton S)
        {
            if (S.Joints[j].TrackingState != JointTrackingState.Tracked)
            {
                return(null);
            }
            SkeletonPoint Sloc = S.Joints[j].Position;

            try
            {
                ColorImagePoint Cloc = sensor.CoordinateMapper.MapSkeletonPointToColorPoint(Sloc, ColorImageFormat.RgbResolution640x480Fps30);
                return(new System.Drawing.Point(Cloc.X, Cloc.Y));
            }
            catch { Console.WriteLine("Error HandD 2 "); };
            return(new System.Drawing.Point(0, 0));
        }
Ejemplo n.º 2
0
        public override void handleSkeleton(Skeleton s, long timestamp, DrawingContext dc, CoordinateMapper cm)
        {
            this.triggeredButton = 0;

            this.leftTracker.handleSkeleton(s, timestamp);
            this.rightTracker.handleSkeleton(s, timestamp);
            SkeletonPoint p;

            if (leftTracker.Triggered)
            {
                p = leftTracker.PushPoint;
            }
            else if (rightTracker.Triggered)
            {
                p = rightTracker.PushPoint;
            }
            else
            {
                return;
            }

            SkeletonPoint hipPoint = s.Joints[JointType.HipCenter].Position;

            if (p.Y > hipPoint.Y)
            {
                return;
            }

            double dx = p.X - hipPoint.X;

            if (dx < -buttonOffset)
            {
                this.triggeredButton = Button.DpadLeft;
            }
            else if (dx < 0)
            {
                this.triggeredButton = Button.DpadUp;
            }
            if (dx > buttonOffset)
            {
                this.triggeredButton = Button.DpadRight;
            }
            else if (dx > 0)
            {
                this.triggeredButton = Button.DpadDown;
            }
        }
Ejemplo n.º 3
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);
                }

                GameProperties.Instance.Ready = false;
                if (skeletons.Length != 0 && skeletons[0] != null)
                {
                    foreach (Skeleton skel in skeletons)
                    {
                        if (skel.TrackingState == SkeletonTrackingState.Tracked)
                        {
                            if (!GameProperties.Instance.Start)
                            {
                                GameProperties.Instance.Ready = true;
                            }
                            SkeletonPoint left  = skel.Joints[JointType.WristLeft].Position;
                            SkeletonPoint right = skel.Joints[JointType.WristRight].Position;
                            if (Math.Abs(left.Y - right.Y) < 0.2f)
                            {
                                if (left.Y < currentY && Math.Abs(left.Y - currentY) > 0.05f)
                                {
                                    GameProperties.Instance.MoveBirdUp(30f * Math.Abs(left.Y - currentY));
                                }

                                currentY = left.Y;
                            }
                            else if ((left.Y - right.Y) < -0.4f)
                            {
                                GameProperties.Instance.MoveBirdLeft(20f * (Math.Abs(right.Y - left.Y) - .5f));
                            }
                            else if ((left.Y - right.Y) > 0.4f)
                            {
                                GameProperties.Instance.MoveBirdRight(20f * (Math.Abs(left.Y - right.Y) - .5f));
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Event handler for Kinect sensor's SkeletonFrameReady event
        /// </summary>
        /// <param name="sender">object sending the event</param>
        /// <param name="e">event arguments</param>
        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)
                        {
                            this.DrawBonesAndJoints(skel, dc);
                        }
                        else if (skel.TrackingState == SkeletonTrackingState.PositionOnly)
                        {
                            dc.DrawEllipse(
                                this.centerPointBrush,
                                null,
                                this.SkeletonPointToScreen(skel.Position),
                                BodyCenterThickness,
                                BodyCenterThickness);

                            SkeletonPoint p = skel.Position;
                            //p.X
                        }
                    }
                }

                // prevent drawing outside of our render area
                this.drawingGroup.ClipGeometry = new RectangleGeometry(new Rect(0.0, 0.0, RenderWidth, RenderHeight));
            }
        }
Ejemplo n.º 5
0
        //need to give projected points for visual user interface help
        //projectedPoint3 will give coordinates for the right ankle posicion
        public SkeletonPoint projectedPointAnkR(Skeleton received)
        {
            //each Ankle should be in line with HipCenter and with the ground
            //the wrist will be near by the corresponding hip side
            //test with other Y coordinate (length between Shoulder to Wrist)
            float projectedAnkRY = received.Joints[JointType.HipRight].Position.Y - alturaPierna;
            float projectedAnkRX = received.Joints[JointType.HipCenter].Position.X;
            float projectedAnkRZ = received.Joints[JointType.HipRight].Position.Z;

            SkeletonPoint projectedAnk = new SkeletonPoint();

            projectedAnk.X = projectedAnkRX;
            projectedAnk.Y = projectedAnkRY;
            projectedAnk.Z = projectedAnkRZ;

            return(projectedAnk);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Maps a SkeletonPoint to lie within our render space and converts to Point
 /// </summary>
 /// <param name="skelpoint">point to map</param>
 /// <returns>mapped point</returns>
 private Point SkeletonPointToScreen(SkeletonPoint skelpoint)
 {
     // Convert point to depth space.
     // We are not using depth directly, but we do want the points in our 640x480 output resolution.
     //DepthImagePoint depthPoint;
     if (this.sensor != null)
     {
         //depthPoint = this.sensor.CoordinateMapper.MapSkeletonPointToDepthPoint(skelpoint, DepthImageFormat.Resolution640x480Fps30);
         System.Drawing.Point depthPoint = SkeletonPointConverter.convert(new JointPosition(skelpoint));
         return(new Point(depthPoint.X, depthPoint.Y));
     }
     else
     {
         System.Drawing.Point p = SkeletonPointConverter.convert(new JointPosition(skelpoint));
         return(new Point(p.X, p.Y));
     }
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Helper method that invokes SpeechRecognized event if there are any event subscribers registered.
 /// </summary>
 /// <param name="phrase">
 /// Speech phrase (text) recognized.
 /// </param>
 /// <param name="semanticValue">
 /// Semantic value associated with recognized speech phrase.
 /// </param>
 /// <param name="sourceAngle">
 /// Best guess at source angle from which speech command originated.
 /// </param>
 private void OnRecognized(string phrase, string semanticValue, double?sourceAngle)
 {
     if (null != SpeechRecognized)
     {
         foreach (Skeleton skeleton in Global.trackedPeople.Keys)
         {
             SkeletonPoint point       = skeleton.Position;
             double        skeletonPos = ((Math.Atan(point.X / point.Z)) * 180 / Math.PI);
             if (Math.Abs(sourceAngle.Value - skeletonPos) <= Global.positionError)
             {
                 SpeechRecognized(this, new SpeechRecognizerEventArgs {
                     Phrase = phrase, SemanticValue = semanticValue, SourceAngle = sourceAngle
                 });
             }
         }
     }
 }
Ejemplo n.º 8
0
        //Winkelberechnung
        private double Winkelberechnung(SkeletonPoint V1, SkeletonPoint V2, string Richtung)
        {
            double gesamt  = 0;
            double Zaehler = 0;
            double nenner1 = 0;
            double nenner2 = 0;

            switch (Richtung)
            {
            case "xy":
                Zaehler = (V1.X * V2.X) + (V1.Y * V2.Y);
                nenner1 = Math.Sqrt((V1.X * V1.X) + (V1.Y * V1.Y));
                nenner2 = Math.Sqrt((V2.X * V2.X) + (V2.Y * V2.Y));
                break;

            case "xz":
                Zaehler = (V1.X * V2.X) + (V1.Z * V2.Z);
                nenner1 = Math.Sqrt((V1.X * V1.X) + (V1.Z * V1.Z));
                nenner2 = Math.Sqrt((V2.X * V2.X) + (V2.Z * V2.Z));
                break;

            case "yz":
                Zaehler = (V1.Y * V2.Y) + (V1.Z * V2.Z);
                nenner1 = Math.Sqrt((V1.Y * V1.Y) + (V1.Z * V1.Z));
                nenner2 = Math.Sqrt((V2.Y * V2.Y) + (V2.Z * V2.Z));
                break;

            case "xyz":
                Zaehler = (V1.X * V2.X) + (V1.Y * V2.Y) + (V1.Z * V2.Z);
                nenner1 = Math.Sqrt(Math.Pow(V1.X, 2) + Math.Pow(V1.Y, 2) + Math.Pow(V1.Z, 2));
                nenner2 = Math.Sqrt(Math.Pow(V2.X, 2) + Math.Pow(V2.Y, 2) + Math.Pow(V2.Z, 2));
                break;
            }

            var nenner = nenner1 * nenner2;

            gesamt = (Math.Acos(Zaehler.Absltdou() / nenner.Absltdou()) * (180 / Math.PI));

            //wenn zähler und nenner null sind
            if (Double.IsNaN(gesamt))
            {
                gesamt = 0;
            }

            return(gesamt);
        }
Ejemplo n.º 9
0
 private Point SkeletonPointToScreen(SkeletonPoint skelpoint)
 {
     // Convert point to depth space.
     // We are not using depth directly, but we do want the points in our 640x480 output resolution.
     try
     {
         DepthImagePoint depthPoint = this.arg.NewSensor.CoordinateMapper.MapSkeletonPointToDepthPoint(
             skelpoint,
             DepthImageFormat.Resolution640x480Fps30);
         return(new Point(depthPoint.X, depthPoint.Y));
     }
     catch (NullReferenceException e)
     {
         Console.WriteLine(e.ToString());
         return(new Point(100, 100));
     }
 }
        private Boolean isInUpperBody(CircleF circle)
        {
            DepthImagePoint point = new DepthImagePoint();

            point.X     = (int)circle.Center.X;
            point.Y     = (int)circle.Center.Y;
            point.Depth = depthRawValues[point.Y * 640 + point.X]; // 640 means the width of the frame.
            point.Depth = point.Depth >> 3;

            SkeletonPoint spoint = myKinect.CoordinateMapper.MapDepthPointToSkeletonPoint(DepthImageFormat.Resolution640x480Fps30, point);

            if (firstSkeleton != null && Math.Abs(spoint.X - spine.X) < 0.2 && Math.Abs(spoint.Y - spine.Y) < 0.1)
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 11
0
        private void DrawEllipse(KinectSensor kinect, SkeletonPoint position)
        {
            const int R = 5;

            ColorImagePoint point = kinect.CoordinateMapper.MapSkeletonPointToColorPoint(position, kinect.ColorStream.Format);

            point.X = (int)ScaleTo(point.X, kinect.ColorStream.FrameWidth, canvasSkeleton.Width);
            point.Y = (int)ScaleTo(point.Y, kinect.ColorStream.FrameHeight, canvasSkeleton.Height);

            canvasSkeleton.Children.Add(new Ellipse()
            {
                Fill   = new SolidColorBrush(Colors.Red),
                Margin = new Thickness(point.X - R, point.Y, 0, 0),
                Width  = R * 2,
                Height = R * 2,
            });
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Helper API to retrieve head points structure from a given skeleton instance
        /// </summary>
        /// <param name="skeletonOfInterest">
        /// skeleton from which head points are to be extracted
        /// </param>
        /// <returns>
        /// HeadPoints that can be passed to Start/Continue tracking APIs
        /// </returns>
        private static Vector3DF[] GetHeadPointsFromSkeleton(Skeleton skeletonOfInterest)
        {
            Vector3DF[] headPoints = null;

            if (skeletonOfInterest != null && skeletonOfInterest.TrackingState == SkeletonTrackingState.Tracked)
            {
                headPoints = new Vector3DF[2];

                SkeletonPoint sp0 = skeletonOfInterest.Joints[JointType.ShoulderCenter].Position;
                headPoints[0] = new Vector3DF(sp0.X, sp0.Y, sp0.Z);

                SkeletonPoint sp1 = skeletonOfInterest.Joints[JointType.Head].Position;
                headPoints[1] = new Vector3DF(sp1.X, sp1.Y, sp1.Z);
            }

            return(headPoints);
        }
        public PruebaAngulos()
        {
            mano          = new Joint();
            mano.Position = SetPosition(-0.87, 4.29, 1.89);

            codo          = new Joint();
            codo.Position = SetPosition(-0.87, 2.31, 1.8);

            hombro          = new Joint();
            hombro.Position = SetPosition(-0.87, 0.52, 3.8);

            objeto = new SkeletonPoint();

            objeto = SetPosition(-0.87, 4.74, 4.1);

            AngleHelper.SetValorAngulos(hombro, mano, codo, objeto);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Funkcja ta przestawia punkt zero z miednicy na poziom glowy
        /// </summary>
        /// <param name="rightHanded"></param>
        /// <param name="skeleton"></param>
        /// <returns></returns>
        private Joint normalizeJoint(bool rightHanded, TrackedSkeleton skeleton)
        {
            Joint head  = skeleton.getJoint(JointType.ShoulderCenter);
            Joint wrist = skeleton.getJoint(JointType.WristRight);

            Joint newJoint = new Joint();

            SkeletonPoint newPoint = new SkeletonPoint()
            {
                X = wrist.Position.X,
                Y = wrist.Position.Y - head.Position.Y
            };

            newJoint.Position = newPoint;

            return(newJoint);
        }
Ejemplo n.º 15
0
        private static SkeletonPoint GetFinger(SkeletonPoint Hand, SkeletonPoint Wrist, SkeletonPoint Elbow, int SkeletonID)
        {
            DepthImagePoint HandD  = myKin.MapSkeletonPointToDepth(Hand, myKin.DepthStream.Format);
            DepthImagePoint WristD = myKin.MapSkeletonPointToDepth(Wrist, myKin.DepthStream.Format);
            //DepthImagePoint ElbowD = myKin.MapSkeletonPointToDepth(ElbowS, myKin.DepthStream.Format);

            //double HandToWrist = Distance(HandS, WristS);
            double WristToElbow = Distance(Wrist, Elbow);
            double maxDistance  = WristToElbow;

            SkeletonPoint max = Hand;

            XYQueue queue = new XYQueue();

            queue.insert(WristD.X, WristD.Y);
            queue.insert(HandD.X, HandD.Y);
            do
            {
                int x, y;
                queue.delete(out x, out y);
                if (x >= 0 && x < myKin.DepthStream.FrameWidth && y >= 0 && y < myKin.DepthStream.FrameHeight) //safheye asli
                {
                    if (GetPersonID(x, y, MapToCamera.Depth) == SkeletonID)                                    //rooye adam
                    {
                        SkeletonPoint point = myKin.MapDepthToSkeletonPoint(myKin.DepthStream.Format, x, y, DepthMap[y * myKin.DepthStream.FrameWidth + x]);
                        if (Distance(Hand, point) < 0.1)          //tooye mohite dast kafe dast
                        {
                            double b = Distance(Elbow, point);
                            if (b >= WristToElbow)                //samte angosht
                            {
                                if (b > maxDistance)              //doortarin angosht
                                {
                                    maxDistance = b;
                                    max         = point;
                                }
                                queue.insert(x + 1, y);
                                queue.insert(x - 1, y);
                                queue.insert(x, y + 1);
                                queue.insert(x, y - 1);
                            }
                        }
                    }
                }
            } while (queue.Count != 0);
            return(max);
        }
Ejemplo n.º 16
0
        static void SkeletonMoved(float time, Skeleton skel)
        {
            // Jank-ass shit
            if (stopwatch == null)
            {
                Console.WriteLine(@"Found skeleton! Recording to Desktop\Dance.csv");

                // Start timer
                stopwatch = Stopwatch.StartNew();

                // Open output file
                file = new System.IO.StreamWriter(@"C:\Users\admin\Desktop\Dance.csv");

                // Write headers
                file.Write("Time");
                foreach (Joint joint in skel.Joints)
                {
                    JointType t = joint.JointType;
                    file.Write("," + t + ".X," + t + ".Y," + t + ".Z");
                }

                //// Write beat header
                //file.Write(",Beat");

                file.WriteLine();
            }

            // Write row
            file.Write(stopwatch.ElapsedMilliseconds / 1000d);
            foreach (Joint joint in skel.Joints)
            {
                if (joint.TrackingState == JointTrackingState.Tracked)
                {
                    SkeletonPoint p = joint.Position;
                    file.Write(",{0},{1},{2}", p.X.ToString("#.##"), p.Y.ToString("#.##"), p.Z.ToString("#.##"));
                }
                else
                {
                    file.Write(",,,");
                }
            }
            //file.Write(",{0}",sBeat);
            file.WriteLine();
            file.Flush();
        }
Ejemplo n.º 17
0
        private void DepthFrameReady(object sender, DepthImageFrameReadyEventArgs e)
        {
            DepthImageFrame frame = e.OpenDepthImageFrame();

            if (frame != null)
            {
                this.FInvalidate = true;
                if (frame.FrameNumber != this.frameindex)
                {
                    this.RebuildBuffer(frame.Format, false);

                    this.frameindex = frame.FrameNumber;
                    frame.CopyDepthImagePixelDataTo(this.depthpixels);
                    int cnt = 0;
                    int img = 0;
                    //DepthImagePixel dp;
                    //dp.
                    this.runtime.Runtime.CoordinateMapper.MapDepthFrameToSkeletonFrame(frame.Format, this.depthpixels, this.skelpoints);
                    for (int h = 0; h < this.height; h++)
                    {
                        for (int w = 0; w < this.width; w++)
                        {
                            //this.runtime.Runtime.CoordinateMapper.
                            //SkeletonPoint sp = frame.MapToSkeletonPoint(w, h);
                            SkeletonPoint sp = this.skelpoints[img];
                            this.world0[cnt]     = sp.X;
                            this.world0[cnt + 1] = sp.Y;
                            this.world0[cnt + 2] = sp.Z;
                            this.world0[cnt + 3] = 1.0f;
                            cnt += 4;
                            img++;
                        }
                    }

                    frame.Dispose();

                    lock (m_lock)
                    {
                        float[] tmp = this.world0;
                        this.world0 = this.world1;
                        this.world1 = tmp;
                    }
                }
            }
        }
Ejemplo n.º 18
0
        //Vektorenberechnung
        private SkeletonPoint VektorAusZweiPunkten(Joint p1, Joint p2, string Richtung)
        {
            var vektorz      = 0;
            var vektorx      = 0;
            var vektory      = 0;
            var scaledJoint1 = p1.ScaleTo(ScreenMaxX, ScreenMaxY, 0.5F, 0.2F);
            var z1           = scaledJoint1.Position.Z * ScreenMaxX;
            var scaledJoint2 = p2.ScaleTo(ScreenMaxX, ScreenMaxY, 0.5F, 0.2F);
            var z2           = scaledJoint2.Position.Z * ScreenMaxX;

            switch (Richtung)
            {
            case "xy":

                vektorx = Convert.ToInt32(scaledJoint1.Position.X.Absltflo() - scaledJoint2.Position.X.Absltflo());
                vektory = Convert.ToInt32(scaledJoint1.Position.Y.Absltflo() - scaledJoint2.Position.Y.Absltflo());
                break;

            case "xz":
                vektorx = Convert.ToInt32(scaledJoint1.Position.X.Absltflo() - scaledJoint2.Position.X.Absltflo());
                vektorz = Convert.ToInt32(z1.Absltflo() - z2.Absltflo());
                break;

            case "yz":
                vektory = Convert.ToInt32(scaledJoint1.Position.Y.Absltflo() - scaledJoint2.Position.Y.Absltflo());
                vektorz = Convert.ToInt32(z1.Absltflo() - z2.Absltflo());
                break;

            case "xyz":
                //vektorx = Convert.ToInt32(scaledJoint1.Position.X - scaledJoint2.Position.X);
                //vektory = Convert.ToInt32(scaledJoint1.Position.Y - scaledJoint2.Position.Y);
                //vektorz = Convert.ToInt32(scaledJoint1.Position.Z - scaledJoint2.Position.Z);
                vektorx = Convert.ToInt32((p1.Position.X * 100) - (p2.Position.X * 100));
                vektory = Convert.ToInt32((p1.Position.Y * 100) - (p2.Position.Y * 100));
                vektorz = Convert.ToInt32((p1.Position.Z * 100) - (p2.Position.Z * 100));
                break;
            }

            SkeletonPoint vektorxyz = new SkeletonPoint();

            vektorxyz.X = vektorx;
            vektorxyz.Y = vektory;
            vektorxyz.Z = vektorz;
            return(vektorxyz);
        }
Ejemplo n.º 19
0
        public void drivingWithTwoHands(SkeletonPoint leftV, SkeletonPoint rightV)
        {
            double coef;

            if (leftV.X > rightV.X)
            {
                if (leftV.Y > rightV.Y)
                {
                    coef = -1; // we must go to right
                }
                else
                {
                    coef = 1; //we must go to left
                }
            }
            else
            {
                coef = (rightV.Y - leftV.Y);
                coef = coef / (rightV.X - leftV.X);
            }

            if (coef > .25 && !isTurning)
            {
                isTurning = true;
                remoteOperation.press_key_down(VirtualKeyCode.LEFT);
                //remoteOperation.message("gauche");
                keysPress.Add(VirtualKeyCode.LEFT);
            }
            if (coef < -0.25 && !isTurning)
            {
                isTurning = true;
                remoteOperation.press_key_down(VirtualKeyCode.RIGHT);
                //remoteOperation.message("droite");
                keysPress.Add(VirtualKeyCode.RIGHT);
            }
            if (coef > -0.25 && coef < .25)
            {
                isTurning = false;
                remoteOperation.press_key_up(VirtualKeyCode.LEFT);
                remoteOperation.press_key_up(VirtualKeyCode.RIGHT);

                keysPress.Remove(VirtualKeyCode.LEFT);
                keysPress.Remove(VirtualKeyCode.RIGHT);
            }
        }
Ejemplo n.º 20
0
 /*/////////////////////////////////////////
  * CO-ORDINATE FUNCTION(S)
  *////////////////////////////////////////
 private Vector2 skeletonToPoint(SkeletonPoint p_point,
                                 KinectManager p_kinect)
 {
     // Function mapping a SkeletonPoint from one space to another...
     if (p_kinect != null &&
         p_kinect.kinect_sensor != null &&
         p_kinect.kinect_sensor.DepthStream != null)
     {
         var depth_pt = p_kinect.kinect_sensor.CoordinateMapper.MapSkeletonPointToDepthPoint(p_point,
                                                                                             p_kinect.kinect_sensor.DepthStream.Format);
         return(new Vector2(depth_pt.X,
                            depth_pt.Y));
     }
     else
     {
         return(Vector2.Zero);
     }
 }
Ejemplo n.º 21
0
        private String GenerateOscDataDump(int counter, string jointName, SkeletonPoint jointPoint, Point jointPosition)
        {
            var dataDump = "";

            if (oscAddress != "")
            {
                dataDump += oscAddress + (counter - 3) + "/" + Math.Round(jointPosition.X, 3) + "\n";
                dataDump += oscAddress + (counter - 2) + "/" + Math.Round(jointPosition.Y, 3) + "\n";
                dataDump += oscAddress + (counter - 1) + "/" + Math.Round(jointPoint.Z, 3) + "\n";
            }
            else
            {
                dataDump += "/skeleton" + counter + "/" + jointName + "/x" + Math.Round(jointPosition.X, 3) + "\n";
                dataDump += "/skeleton" + counter + "/" + jointName + "/y" + Math.Round(jointPosition.Y, 3) + "\n";
                dataDump += "/skeleton" + counter + "/" + jointName + "/z" + Math.Round(jointPoint.Z, 3) + "\n";
            }
            return(dataDump);
        }
Ejemplo n.º 22
0
        private void ScalePosition(FrameworkElement element, Joint joint)
        {
            //convert the value to X/Y
            SkeletonPoint point = new SkeletonPoint
            {
                X = ScaleVector(screenWidth, joint.Position.X),
                Y = ScaleVector(screenHeight, -joint.Position.Y),
                Z = joint.Position.Z
            };

            Joint scaledJoint = joint;

            scaledJoint.TrackingState = JointTrackingState.Tracked;
            scaledJoint.Position      = point;

            Canvas.SetLeft(element, scaledJoint.Position.X);
            Canvas.SetTop(element, scaledJoint.Position.Y);
        }
Ejemplo n.º 23
0
        public bool ComparePoints(SkeletonPoint point1, SkeletonPoint point2)
        {
            bool valid = true;

            if (Math.Abs(point1.X - point2.X) > 3)
            {
                valid = false;
            }
            if (Math.Abs(point1.Y - point2.Y) > 3)
            {
                valid = false;
            }
            if (Math.Abs(point1.Z - point2.Y) > 3)
            {
                valid = false;
            }
            return(valid);
        }
Ejemplo n.º 24
0
        // called for every skeleton frame
        protected override bool IsGestureValid(Skeleton skeletonData)
        {
            // current right hand position
            var currentHandRightPoisition = skeletonData.Joints[JointType.HandRight].Position;

            // current right hand should be on the left of the previous right hand position,
            // i.e., the right hand is moving to the left
            if (validatePosition.X < currentHandRightPoisition.X)
            {
                // if the right hand is moving to the right, stop doing gesture recognition
                return(false);
            }
            // update the validatePosition using the current right hand position
            validatePosition = currentHandRightPoisition;

            // gesture so far so good
            return(true);
        }
Ejemplo n.º 25
0
        public static Joint ScaleTo(this Joint joint, int width, int height, float skeletonMaxX, float skeletonMaxY, bool originCenter)
        {
            if (!originCenter)
            {
                return(Coding4Fun.Kinect.Wpf.SkeletalExtensions.ScaleTo(joint, width, height, skeletonMaxX, skeletonMaxY));
            }

            SkeletonPoint pos = new SkeletonPoint()
            {
                X = Scale(width, skeletonMaxX, joint.Position.X),
                Y = Scale(height, skeletonMaxY, -joint.Position.Y),
                Z = joint.Position.Z,
            };

            joint.Position = pos;

            return(joint);
        }
Ejemplo n.º 26
0
            /// <summary>
            /// Calcula y devuelve por referencia unos valores esenciales para la deteccion de movimientos
            /// </summary>
            /// <param name="punto_base">punto base</param>
            /// <param name="punto_inicial">punto inicial</param>
            /// <param name="punto_actual">punto actual</param>
            /// <param name="angulo">angulo entre el vector base_inicial (vector desde punto_base a punto_inicial) y el vector
            /// base_actual (vector desde punto_base a punto_actual)</param>
            /// <param name="diferencia_X">diferencia_X como valor absoluto de la diferencia entre la componente X de punto_actual
            /// y punto_inicial</param>
            /// <param name="diferencia_Z">diferencia_Z como la diferencia entre la componente Z de punto_actual y punto_inicial</param>
            public void valores_base(SkeletonPoint punto_base, SkeletonPoint punto_inicial, SkeletonPoint punto_actual,
                                     out double angulo, out double diferencia_X, out double diferencia_Z)
            {
                SkeletonPoint vector_base_inicial = new SkeletonPoint();
                SkeletonPoint vector_base_actual  = new SkeletonPoint();

                vector_base_inicial.X = punto_inicial.X - punto_base.X;
                vector_base_inicial.Y = punto_inicial.Y - punto_base.Y;
                vector_base_inicial.Z = punto_inicial.Z - punto_base.Z;
                vector_base_actual.X  = punto_actual.X - punto_base.X;
                vector_base_actual.Y  = punto_actual.Y - punto_base.Y;
                vector_base_actual.Z  = punto_actual.Z - punto_base.Z;

                angulo = Math.Acos(producto_escalar(vector_base_inicial, vector_base_actual) /
                                   (modulo(vector_base_inicial) * modulo(vector_base_actual))) / Math.PI * 180.0;
                diferencia_X = Math.Abs(punto_actual.X - punto_inicial.X);
                diferencia_Z = punto_actual.Z - punto_inicial.Z;
            }
Ejemplo n.º 27
0
        public PruebaAngulos()
        {
            hombro          = new Joint();
            hombro.Position = SetPosition(2.3, 1.21, -1.67);

            codo          = new Joint();
            codo.Position = SetPosition(2.3, 0.98, -0.78);

            mano          = new Joint();
            mano.Position = SetPosition(2.3, 1.42, 0.3);

            objeto = new SkeletonPoint();

            objeto = SetPosition(2.3, 0.25, -0.17);
            AngleHelper a = new AngleHelper();

            a.SetValorAngulos(new Puntos(hombro, codo, mano, objeto));
        }
Ejemplo n.º 28
0
        public DepthImagePoint GetJointPosition(KinectSensor sensor, AllFramesReadyEventArgs e, JointType jointType)
        {
            Skeleton        skeleton   = GetTrackedSkeleton(e);
            DepthImagePoint depthPoint = new DepthImagePoint();

            JointDetected = false;

            if (SkeletonDetected == true)
            {
                Joint joint = skeleton.Joints[jointType];

                JointDetected = true;
                SkeletonPoint jointPoint = joint.Position;
                depthPoint = sensor.MapSkeletonPointToDepth(jointPoint, DepthImageFormat.Resolution320x240Fps30);
            }

            return(depthPoint);
        }
Ejemplo n.º 29
0
        //alternativ winkelberechnung x
        private double WinkelBerechnungX(SkeletonPoint V1)
        {
            double gesamt  = 0;
            double Zaehler = 0;
            double nenner  = 0;

            Zaehler = V1.X;
            nenner  = Math.Sqrt(Math.Pow(V1.X, 2) + Math.Pow(V1.Y, 2) + Math.Pow(V1.Z, 2));
            gesamt  = Math.Asin(Zaehler.Absltdou() / nenner.Absltdou()) * (180 / Math.PI);

            //wenn zähler und nenner null sind
            if (Double.IsNaN(gesamt))
            {
                gesamt = 0;
            }

            return(gesamt);
        }
        /*
         *
         * 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);
         *      }
         *  }
         *
         *
         *  if (skeletons.Length != 0)
         *  {
         *      foreach (Skeleton skel in skeletons)
         *      {
         *          //RenderClippedEdges(skel, dc);
         *
         *          if (skel.TrackingState == SkeletonTrackingState.Tracked)
         *          {
         *              this.Joints(skel);
         *          }
         *      }
         *  }
         *
         * }
         */
        private void DibujaElipse(float x, float y, float z)
        {
            SkeletonPoint point = new SkeletonPoint();

            point.X = x;
            point.Y = y;
            point.Z = z;

            Point   ell = this.SkeletonPointToScreen(point);
            Ellipse aux = new Ellipse();

            aux.Width  = 20;
            aux.Height = 20;
            aux.Fill   = Brushes.Orange;
            Canvas.SetTop(aux, ell.Y);
            Canvas.SetLeft(aux, ell.X);
            this.SkeletonControl.Children.Add(aux);
        }
Ejemplo n.º 31
0
 private Point SkeletonPointToScreen(SkeletonPoint skelpoint)
 {
     DepthImagePoint point = this._sensor.CoordinateMapper.MapSkeletonPointToDepthPoint(skelpoint, DepthImageFormat.Resolution640x480Fps30);
     return new Point((double)point.X, (double)point.Y);
 }
Ejemplo n.º 32
0
 internal Joint(JointType jointType, SkeletonPoint skeletonPoint, JointTrackingState jointTrackingState)
 {
     JointType = jointType;
     Position = skeletonPoint;
     TrackingState = jointTrackingState;
 }
Ejemplo n.º 33
0
		/// <summary>
		/// Absolutes to relative.
		/// </summary>
		/// <returns>The to relative.</returns>
        /// <param name="point">point.</param>
        private static Vector3 ToVec3(SkeletonPoint point)
        {
            return new Vector3(point.X, point.Y, point.Z) * 1000;
        }
Ejemplo n.º 34
0
		private Joint ScaleTo(Joint joint, int width, int height, float skeletonMaxX, float skeletonMaxY)
		{
			SkeletonPoint pos = new SkeletonPoint()
			{
				X = Scale(width, skeletonMaxX, joint.Position.X),
				Y = Scale(height, skeletonMaxY, -joint.Position.Y),
				Z = joint.Position.Z,
			};

			Joint j = new Joint()
			{
				TrackingState = joint.TrackingState,
				Position = pos
			};

			return j;
		}