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);
                    }
                }
            }
        }
Exemplo n.º 2
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
      }