private void BodyReader_FrameArrived(object sender, BodyFrameArrivedEventArgs e)
        {
            using (BodyFrame frame = e.FrameReference.AcquireFrame())
            {
                if (frame != null)
                {
                    _floor = frame.Floor();
                    _body  = frame.Body();

                    if (_floor != null && _body != null)
                    {
                        CameraSpacePoint wrist3D = _body.Joints[JointType.HandLeft].Position;
                        Point            wrist2D = wrist3D.ToPoint();

                        double distance = _floor.DistanceFrom(wrist3D);
                        int    floorY   = _floor.FloorY((int)wrist2D.X, (ushort)(wrist3D.Z * 1000));

                        TblDistance.Text = distance.ToString("N2");

                        Canvas.SetLeft(ImgHand, wrist2D.X - ImgHand.Width / 2.0);
                        Canvas.SetTop(ImgHand, wrist2D.Y - ImgHand.Height / 2.0);
                        Canvas.SetLeft(ImgFloor, wrist2D.X - ImgFloor.Width / 2.0);
                        Canvas.SetTop(ImgFloor, floorY - ImgFloor.Height / 2.0);
                    }
                }
            }
        }
Exemple #2
0
    void SetVertexAtPosition(CameraSpacePoint vertex, Transform vertexTransform, FrameView frameView)
    {
        Vector2 position = vertex.ToPoint(visualization, coordinateMapper);

        if (float.IsInfinity(position.x) || float.IsInfinity(position.y))
        {
            if (vertexTransform.gameObject.activeSelf)
            {
                vertexTransform.gameObject.SetActive(false);
            }
        }
        else
        {
            frameView.SetPositionOnFrame(ref position);

            if (!vertexTransform.gameObject.activeSelf)
            {
                vertexTransform.gameObject.SetActive(true);
            }

            vertexTransform.localPosition = position;
        }
    }
 /// <summary>
 /// Calculates the angle and updates the arc according to the specifed points.
 /// </summary>
 /// <param name="start">The starting point.</param>
 /// <param name="middle">The middle point.</param>
 /// <param name="end">The end point.</param>
 /// <param name="desiredRadius">The desired arc radius.</param>
 public void Update(CameraSpacePoint start, CameraSpacePoint middle, CameraSpacePoint end, double desiredRadius = 0)
 {
     Update(start.ToPoint(Visualization.Color), middle.ToPoint(Visualization.Color), end.ToPoint(Visualization.Color), desiredRadius);
 }
Exemple #4
0
      private void BodyReader_FrameArrived(object sender, BodyFrameArrivedEventArgs e)
      {
          int adult    = 0;
          int children = 0;

          using (BodyFrame frame = e.FrameReference.AcquireFrame())
          {
              if (frame != null)
              {
                  _floor = frame.Floor();
                  _body  = frame.Body();

                  if (_floor != null && _body != null)
                  {
                      CameraSpacePoint wrist3D  = _body.Joints[JointType.Head].Position;
                      Point            wrist2D  = wrist3D.ToPoint();
                      double           distance = _floor.DistanceFrom(wrist3D);
                      text = Convert.ToDouble(distance.ToString("N2"));
                      //float
                      text += 0.18;
                      if (T == 0)
                      {
                          cache = text;
                      }
                      int floorY = _floor.FloorY((int)wrist2D.X, (ushort)(wrist3D.Z * 1000));

                      Row.Text = Convert.ToString(wrist2D);

                      Cache.Text       = Convert.ToString(cache);
                      TblDistance.Text = Convert.ToString(text);
                      Canvas.SetLeft(ImgHand, wrist2D.X - ImgHand.Width / 2.0);
                      Canvas.SetTop(ImgHand, wrist2D.Y - ImgHand.Height / 2.0);
                      Canvas.SetLeft(ImgFloor, wrist2D.X - ImgFloor.Width / 2.0);
                      Canvas.SetTop(ImgFloor, floorY - ImgFloor.Height / 2.0);
                      if (cache > 1.6)
                      {
                          if (T == 0)
                          {
                              adult += 1;
                              T      = 1;
                              // distance = 0;
                              //textBlock1.Text = Convert.ToString("成人人數:" + adult);
                              //IO file
                              StreamWriter tall = new StreamWriter(@"C:\Users\joy22\Pictures\tall.txt");
                              tall.WriteLine(Convert.ToString(cache * 100));
                              tall.Close();

                              //Take Picture
                              if (this.wbmp != null)
                              {
                                  // create a png bitmap encoder which knows how to save a .png file
                                  BitmapEncoder encoder = new PngBitmapEncoder();
                                  // create frame from the writable bitmap and add to encoder
                                  encoder.Frames.Add(BitmapFrame.Create(this.wbmp));
                                  string myPhotos = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
                                  string path     = Path.Combine(myPhotos, "Upload" + ".png");
                                  // FileStream is IDisposable
                                  using (FileStream fs = new FileStream(path, FileMode.Create))
                                  { encoder.Save(fs); }
                              }
                          }
                      }
                      if (cache < 1.6 && T == 0 && text != 0)
                      {
                          T        = 1;
                          children = children + 1;
                          StreamWriter tall = new StreamWriter(@"C:\Users\joy22\Pictures\tall.txt");
                          tall.WriteLine(Convert.ToString(cache * 100));
                          tall.Close();
                          //textBlock2.Text = Convert.ToString("孩童人數::" + children);
                          //Take Picture
                          if (this.wbmp != null)
                          {
                              // create a png bitmap encoder which knows how to save a .png file
                              BitmapEncoder encoder = new PngBitmapEncoder();
                              // create frame from the writable bitmap and add to encoder
                              encoder.Frames.Add(BitmapFrame.Create(this.wbmp));
                              string myPhotos = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
                              string path     = Path.Combine(myPhotos, "Upload" + ".png");
                              // FileStream is IDisposable
                              using (FileStream fs = new FileStream(path, FileMode.Create))
                              { encoder.Save(fs); }
                          }
                      }
                      if (((cache - 0.04) > text) || ((cache + 0.04) < text))
                      {
                          // textBlock.Text = "m";
                          T        = 0;
                          cache    = 0;
                          text     = 0;
                          distance = 0;
                      }
                      if (adult != 0 || children != 0)
                      {
                          textBlock1.Text = Convert.ToString("成人人數:" + adult);
                          textBlock2.Text = Convert.ToString("孩童人數::" + children);
                      }
                  }
              }
          }
          //Tall
      }
 /// <summary>
 /// Converts the specified CameraSpacePoint into a 2-D point.
 /// </summary>
 /// <param name="position">The CameraSpacePoint to convert.</param>
 /// <param name="visualization">The type of the conversion (color, depth, or infrared).</param>
 /// <returns>The corresponding 2-D point.</returns>
 public static Point ToPoint(this CameraSpacePoint position, Visualization visualization)
 {
     return(position.ToPoint(visualization, KinectSensor.GetDefault().CoordinateMapper));
 }
 /// <summary>
 /// Calculates the angle and updates the arc according to the specifed points.
 /// </summary>
 /// <param name="start">The starting point.</param>
 /// <param name="middle">The middle point.</param>
 /// <param name="end">The end point.</param>
 /// <param name="desiredRadius">The desired arc radius.</param>
 public void Update(CameraSpacePoint start, CameraSpacePoint middle, CameraSpacePoint end, double desiredRadius = 0)
 {
     Update(start.ToPoint(Visualization.Color), middle.ToPoint(Visualization.Color), end.ToPoint(Visualization.Color), desiredRadius);
 }
        private void FaceReader_FrameArrived(object sender, HighDefinitionFaceFrameArrivedEventArgs args)
        {
            using (var frame = args.FrameReference.AcquireFrame())
            {
                if (frame != null && frame.IsFaceTracked)
                {
                    Face face = frame.Face();

                    if (_showAllPoints)
                    {
                        // Display all face points.
                        if (_ellipses.Count == 0)
                        {
                            for (int index = 0; index < face.Vertices.Count; index++)
                            {
                                Ellipse ellipse = new Ellipse
                                {
                                    Width  = 2.0,
                                    Height = 2.0,
                                    Fill   = new SolidColorBrush(Colors.Orange)
                                };

                                _ellipses.Add(ellipse);

                                canvas.Children.Add(ellipse);
                            }
                        }

                        for (int index = 0; index < face.Vertices.Count; index++)
                        {
                            Ellipse ellipse = _ellipses[index];

                            CameraSpacePoint vertex = face.Vertices[index];
                            PointF           point  = vertex.ToPoint(Visualization.Infrared);

                            Canvas.SetLeft(ellipse, point.X - ellipse.Width / 2.0);
                            Canvas.SetTop(ellipse, point.Y - ellipse.Height / 2.0);
                        }
                    }
                    else
                    {
                        // Display basic points only.
                        PointF pointEyeLeft    = face.EyeLeft.ToPoint(Visualization.Infrared);
                        PointF pointEyeRight   = face.EyeRight.ToPoint(Visualization.Infrared);
                        PointF pointCheekLeft  = face.CheekLeft.ToPoint(Visualization.Infrared);
                        PointF pointCheekRight = face.CheekRight.ToPoint(Visualization.Infrared);
                        PointF pointNose       = face.Nose.ToPoint(Visualization.Infrared);
                        PointF pointMouth      = face.Mouth.ToPoint(Visualization.Infrared);
                        PointF pointChin       = face.Chin.ToPoint(Visualization.Infrared);
                        PointF pointForehead   = face.Forehead.ToPoint(Visualization.Infrared);

                        Canvas.SetLeft(eyeLeft, pointEyeLeft.X - eyeLeft.Width / 2.0);
                        Canvas.SetTop(eyeLeft, pointEyeLeft.Y - eyeLeft.Height / 2.0);

                        Canvas.SetLeft(eyeRight, pointEyeRight.X - eyeRight.Width / 2.0);
                        Canvas.SetTop(eyeRight, pointEyeRight.Y - eyeRight.Height / 2.0);

                        Canvas.SetLeft(cheekLeft, pointCheekLeft.X - cheekLeft.Width / 2.0);
                        Canvas.SetTop(cheekLeft, pointCheekLeft.Y - cheekLeft.Height / 2.0);

                        Canvas.SetLeft(cheekRight, pointCheekRight.X - cheekRight.Width / 2.0);
                        Canvas.SetTop(cheekRight, pointCheekRight.Y - cheekRight.Height / 2.0);

                        Canvas.SetLeft(nose, pointNose.X - nose.Width / 2.0);
                        Canvas.SetTop(nose, pointNose.Y - nose.Height / 2.0);

                        Canvas.SetLeft(mouth, pointMouth.X - mouth.Width / 2.0);
                        Canvas.SetTop(mouth, pointMouth.Y - mouth.Height / 2.0);

                        Canvas.SetLeft(chin, pointChin.X - chin.Width / 2.0);
                        Canvas.SetTop(chin, pointChin.Y - chin.Height / 2.0);

                        Canvas.SetLeft(forehead, pointForehead.X - forehead.Width / 2.0);
                        Canvas.SetTop(forehead, pointForehead.Y - forehead.Height / 2.0);
                    }
                }
            }
        }
        void Reader_MultiSourceFrameArrived(object sender, MultiSourceFrameArrivedEventArgs e)
        {
            var reference = e.FrameReference.AcquireFrame();

            // Color
            using (var frame = reference.ColorFrameReference.AcquireFrame())
            {
                if (frame != null)
                {
                    if (_mode == CameraMode.Color)
                    {
                        camera.Source = frame.ToBitmap();
                    }
                }
            }

            // Depth
            using (var frame = reference.DepthFrameReference.AcquireFrame())
            {
                if (frame != null)
                {
                    if (_mode == CameraMode.Depth)
                    {
                        camera.Source = frame.ToBitmap();
                    }
                }
            }

            // Infrared
            using (var frame = reference.InfraredFrameReference.AcquireFrame())
            {
                if (frame != null)
                {
                    if (_mode == CameraMode.Infrared)
                    {
                        camera.Source = frame.ToBitmap();
                    }
                }
            }

            // Body
            using (var frame = reference.BodyFrameReference.AcquireFrame())
            {
                //BURADA - Text e veri kaydetme class'ından instance alıyoruz
                DataSave ds = new DataSave();
                Distance bs = new Distance();



                if (frame != null)
                {
                    canvas.Children.Clear();
                    _floor = frame.Floor();
                    _body  = frame.Body();



                    _bodies = new Body[frame.BodyFrameSource.BodyCount];

                    frame.GetAndRefreshBodyData(_bodies);

                    foreach (var body in _bodies)
                    {
                        if (body.IsTracked)
                        {
                            // COORDINATE MAPPING
                            foreach (Joint joint in body.Joints.Values)
                            {
                                if (joint.TrackingState == TrackingState.Tracked)
                                {
                                    // 3D space point
                                    CameraSpacePoint jointPosition = joint.Position;

                                    if (jointPosition.Z < 0)
                                    {
                                        jointPosition.Z = InferredZPositionClamp;
                                    }

                                    // 2D space point
                                    Point point = new Point();

                                    if (_mode == CameraMode.Color)
                                    {
                                        ColorSpacePoint colorPoint = _sensor.CoordinateMapper.MapCameraPointToColorSpace(jointPosition);

                                        point.X = float.IsInfinity(colorPoint.X) ? 0 : colorPoint.X;
                                        point.Y = float.IsInfinity(colorPoint.Y) ? 0 : colorPoint.Y;
                                    }
                                    else if (_mode == CameraMode.Depth || _mode == CameraMode.Infrared) // Change the Image and Canvas dimensions to 512x424
                                    {
                                        DepthSpacePoint depthPoint = _sensor.CoordinateMapper.MapCameraPointToDepthSpace(jointPosition);

                                        point.X = float.IsInfinity(depthPoint.X) ? 0 : depthPoint.X;
                                        point.Y = float.IsInfinity(depthPoint.Y) ? 0 : depthPoint.Y;
                                    }

                                    // Draw
                                    Ellipse ellipse = new Ellipse
                                    {
                                        Fill   = Brushes.Red,
                                        Width  = 30,
                                        Height = 30
                                    };



                                    //bool legUp = false;
                                    //Point currentPoint = point;
                                    //if (legUp && Math.Abs(currentPoint.Y - previousPoint.Y) < 15)
                                    //{
                                    //    legUp = false;
                                    //    stepCount++;

                                    //}
                                    //else if (!legUp && Math.Abs(currentPoint.Y - previousPoint.Y) > 15)
                                    //{
                                    //    legUp = true;
                                    //    stepCount++;
                                    //}
                                    //previousPoint = currentPoint;



                                    Point currentPoint = point;
                                    if (Math.Abs(currentPoint.Y - previousPoint.Y) > 5)
                                    {
                                        stepCount++;
                                    }
                                    else if (Math.Abs(currentPoint.Y - previousPoint.Y) < 5)
                                    {
                                    }
                                    previousPoint = currentPoint;



                                    //if (!legUp && right > left + 15)
                                    //{
                                    //    legUp = true;
                                    //    stepCount++;

                                    //}
                                    //else if (legUp && left > right + 15)
                                    //{
                                    //    legUp = false;
                                    //    stepCount++;

                                    //}
                                    //previousPoint = currentPoint;


                                    //BURADA - Gelen X Y Z verileri text e kaydedilir.
                                    ds.dataSave(stepCount, joint.JointType.ToString(), point.X, point.Y, jointPosition.Z, joint.JointType.ToString());

                                    Canvas.SetLeft(ellipse, point.X - ellipse.Width / 2);
                                    Canvas.SetTop(ellipse, point.Y - ellipse.Height / 2);
                                }
                            }
                        }
                    }

                    if (_floor != null && _body != null)
                    {
                        CameraSpacePoint ankle3D = _body.Joints[JointType.FootLeft].Position;

                        Point ankle2D = ankle3D.ToPoint();

                        double distance = _floor.DistanceFrom(ankle3D);
                        int    floorY   = _floor.FloorY((int)ankle2D.X, (ushort)(ankle3D.Z * 1000));

                        // double speed;
                        string time = DateTime.Now.ToString("ss.fff");


                        //spped= distance/time bunu yazıdırcaz
                        //speed = (Double.Parse(distance)) / Double.Parse   (time)).ToString();

                        // speed = (double(distance )/ time).ToString;



                        //int adimSayisi = 0;
                        //legUp = false;
                        //if (distance==0)
                        //{
                        //    legUp = false;
                        //    t2 = currentTime;
                        //}
                        //else
                        //{
                        //    legUp = true;
                        //    adimSayisi += 1;
                        //    t1= currentTime;
                        //    time = Convert.ToInt32(t2) - Convert.ToInt32(t1);
                        //}

                        TblDistance.Text = distance.ToString("N2");
                        bs.dataSave(distance, time);



                        Canvas.SetLeft(ImgFoot, ankle2D.X - ImgFoot.Width / 2.0);
                        Canvas.SetTop(ImgFoot, ankle2D.Y - ImgFoot.Height / 2.0);
                        Canvas.SetLeft(ImgFloor, ankle2D.X - ImgFloor.Width / 2.0);
                        Canvas.SetTop(ImgFloor, floorY - ImgFloor.Height / 2.0);
                    }
                }
            }
        }