Exemple #1
0
        public DepthImagePoint[] CalculateConvexHull()
        {
            var hull = new DepthImagePoint[100];

            // Sort the points by x-coordinate
            var sortedPoints = Points.Where(HasDepth).OrderBy(p => p.X);

            // Calculate the lower hull
            var n = 0;
            foreach (var p in sortedPoints)
            {
                while (n >= 2 && !Util.IsLeftTurn(hull[n - 2], hull[n - 1], p)) n--;
                hull[n++] = p;
            }

            // Calculate the upper hull
            var min = n + 1;
            foreach (var p in sortedPoints.Reverse())
            {
                while (n >= min && !Util.IsLeftTurn(hull[n - 2], hull[n - 1], p)) n--;
                hull[n++] = p;
            }

            // Return the hull elements (the last point is the same as the first)
            return hull.Take(n - 1).ToArray();
        }
        /// <summary>
        /// Map PointDepth3D to PointSkeleton3D
        /// </summary>
        /// <param name="depthImageFormat"></param>
        /// <param name="pointDepth3D"></param>
        /// <returns></returns>
        public PointSkeleton3D MapDepthPointToSketelonPoint(DepthImageFormat depthImageFormat, PointDepth3D pointDepth3D)
        {
            DepthImagePoint point = new DepthImagePoint();
            point.X = pointDepth3D.X;
            point.Y = pointDepth3D.Y;
            point.Depth = pointDepth3D.Depth;

            return new PointSkeleton3D(mapper.MapDepthPointToSkeletonPoint(depthImageFormat, point));
        }
        /// <summary>
        /// Maps a point in the depth image to a point in the color image.
        /// </summary>
        /// <param name="x">x coordinate in the depth image.</param>
        /// <param name="y">y coordinate in the depth image.</param>
        /// <param name="depth">correspoinding depth at (x, y).</param>
        /// <returns></returns>
        public ColorImagePoint MapDepthPointToColorPoint(int x, int y, int depth)
        {
            var dp = new DepthImagePoint() {
            X = x,
            Y = y,
            Depth = depth
              };

              return mapper.MapDepthPointToColorPoint(dif, dp, cif);
        }
        public MainWindow()
        {
            InitializeComponent();

            _SkeletonBrushes = new Brush[] { Brushes.Black, Brushes.Crimson, Brushes.Indigo, Brushes.DodgerBlue, Brushes.Purple, Brushes.Pink };

            KinectSensor.KinectSensors.StatusChanged += KinectSensors_StatusChanged;
            this.KinectDevice = KinectSensor.KinectSensors.FirstOrDefault(x => x.Status == KinectStatus.Connected);
            _previousHandPosition = new DepthImagePoint();
        }
        public SkeletonPoint MapDepthPointToSkeletonPoint(int x, int y, int depth)
        {
            var depthPoint = new DepthImagePoint() {
            X = x,
            Y = y,
            Depth = depth
              };

              return MapDepthPointToSkeletonPoint(depthPoint);
        }
 private static SkeletonPoint? FindDepth(KinectSensor sensor, DepthImagePixel[] depthPixels, Point point, int idx)
 {
     if (idx >= 0)
     {
         if (!depthPixels[idx].IsKnownDepth)
             return null;
         var dp = new DepthImagePoint() { X = (int)point.X, Y = (int)point.Y, Depth = depthPixels[idx].Depth };
         return sensor.CoordinateMapper.MapDepthPointToSkeletonPoint(DepthImageFormat.Resolution640x480Fps30, dp);
     }
     return null;
 }
Exemple #7
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;
        }
 public CompositePlayer[] Trigger(int wait)
 {
     var sp = Task.Run(() => skeleton.GetSkeletons(wait));
     var dp = Task.Run(() =>
         {
             var result = depth.Get(wait, (pixel, point, size) =>
             {
                 if (!pixel.IsKnownDepth)
                     return null;
                 var dip = new DepthImagePoint()
                 {
                     X = point.X,
                     Y = point.Y,
                     Depth = pixel.Depth
                 };
                 return (DepthImageIndexedPoint?)new DepthImageIndexedPoint()
                 {
                     Index = pixel.PlayerIndex,
                     Point = dip
                 };
             }).ToArray().Where(p => p.HasValue).Select(p => p.Value).ToArray();
             return result;
         });
     dp.Wait();
     var points = dp.Result;
     Skeleton[] skeletons = new Skeleton[0];
     if (points.Any(p => p.Index >= 1 && p.Index <= 6))
     {
         sp.Wait();
         skeletons = sp.Result;
     }
     return points.GroupBy(p => p.Index).Select(group => new CompositePlayer()
     {
         DepthPoints = group.Select(g => g.Point).ToArray(),
         PlayerId = group.Key,
         Skeleton = (group.Key >= 1 && group.Key <= 6) ? skeletons[group.Key - 1] : null
     }).ToArray();
 }
 public float[] ToColorSpace(CoordinateMapper mapper, DepthImagePoint point, DepthImageFormat format, float zTune = 0)
 {
     var sp = mapper.MapDepthPointToSkeletonPoint(format, point);
     return ToColorSpace(mapper, sp, zTune);
 }
Exemple #10
0
        private Point posionScale(SkeletonPoint point)
        {
            DepthImagePoint depthPoint = this._sensor.CoordinateMapper.MapSkeletonPointToDepthPoint(point, DepthImageFormat.Resolution640x480Fps30);

            return(new Point(depthPoint.X, depthPoint.Y));
        }
        int find_code(ColorImageFrame colorFrame, DepthImageFrame depthFrame)
        {
            ZXing.Kinect.BarcodeReader reader = new ZXing.Kinect.BarcodeReader();
            if (colorFrame != null)
            {
                //Decode the colorFrame
                var result = reader.Decode(colorFrame);
                if (result != null)
                {
                    string val = result.Text;
                    int code_num = Convert.ToInt32(val);
                    double center_x = result.ResultPoints[0].X + 0.5 * (result.ResultPoints[2].X - result.ResultPoints[0].X);
                    double center_y = result.ResultPoints[0].Y + 0.5 * (result.ResultPoints[2].Y - result.ResultPoints[0].Y);

                    code_size = new Point((result.ResultPoints[2].X - result.ResultPoints[0].X), (result.ResultPoints[2].Y - result.ResultPoints[0].Y));

                    // Must mirror the coordinate here -- the depth frame comes in mirrored.
                    center_x = 640 - center_x;

                    // Map the color frame onto the depth frame
                    DepthImagePixel[] depthPixel = new DepthImagePixel[depthFrame.PixelDataLength];
                    depthFrame.CopyDepthImagePixelDataTo(depthPixel);
                    DepthImagePoint[] depthImagePoints = new DepthImagePoint[sensor.DepthStream.FramePixelDataLength];
                    sensor.CoordinateMapper.MapColorFrameToDepthFrame(sensor.ColorStream.Format, sensor.DepthStream.Format, depthPixel, depthImagePoints);

                    // Get the point in the depth frame at the center of the barcode
                    int center_point_color_index = (int)center_y * 640 + (int)center_x;
                    DepthImagePoint converted_depth_point = depthImagePoints[center_point_color_index];
                    Point p = new Point(converted_depth_point.X, converted_depth_point.Y);
                    code_points[code_num] = p;

                    Console.WriteLine("Found code " + code_num + " at (" + center_x + ", " + center_y + ") in color coordinates.");
                    Console.WriteLine("Translated to (" + p.X + ", " + p.Y + ") in depth coordinates.");
                    return code_num;
                }
            }

            return -1;
        }
        private void GrayscaleData(byte[] pixelData)
        {
            // Mapping depth to color
            var mapper = new CoordinateMapper(sensor);
            var depthPoints = new DepthImagePoint[640 * 480];
            mapper.MapColorFrameToDepthFrame(ColorImageFormat.RgbResolution640x480Fps30, DepthImageFormat.Resolution640x480Fps30, depthImagePixels, depthPoints);

            for (int i = 0; i < depthPoints.Length; i++)
            {
                var point = depthPoints[i];
                if (point.Depth > 600 || KinectSensor.IsKnownPoint(point))
                {
                    var pixelDataIndex = i * 4;
                    var maxValue = Math.Max(pixelData[pixelDataIndex], Math.Max(pixelData[pixelDataIndex + 1], pixelData[pixelDataIndex + 2]));
                    pixelData[pixelDataIndex] = maxValue;
                    pixelData[pixelDataIndex + 1] = maxValue;
                    pixelData[pixelDataIndex + 2] = maxValue;
                }
            }
        }
 //
 // Summary:
 //     Tests whether the DepthImagePoint has a known value.
 //
 // Parameters:
 //   depthImagePoint:
 //     The DepthImagePoint to test.
 //
 // Returns:
 //     Rreturns false if depth value == 0.
 public static bool IsKnownPoint(DepthImagePoint depthImagePoint);
Exemple #14
0
        private DepthImagePoint MapSkeletonPointToDepth(SkeletonPoint skelpoint, DepthImageFormat depthImageFormat)
        {
            DepthImagePoint rPoint = new DepthImagePoint();
            rPoint.X = 0;
            rPoint.Y = 0;

            if (skelpoint.Z > _FLT_EPSILON)
            {
                rPoint.X = (int)(0.5 + skelpoint.X * (_NUI_CAMERA_COLOR_NOMINAL_FOCAL_LENGTH_IN_PIXELS / skelpoint.Z) / 640.0);
                rPoint.Y = (int)(0.5 - skelpoint.Y * (_NUI_CAMERA_COLOR_NOMINAL_FOCAL_LENGTH_IN_PIXELS / skelpoint.Z) / 480.0);
                return rPoint;
            }

            //Taken from: pytools.codeplex.com -> PyKinect-> nui -> __init__.py
            //def skeleton_to_depth_image(vPoint, scaleX = 1, scaleY = 1):
            //    """Given a Vector4 returns X and Y coordinates fo display on the screen.  Returns a tuple depthX, depthY"""
            //    if vPoint.z > _FLT_EPSILON:
            //       ##
            //       ## Center of depth sensor is at (0,0,0) in skeleton space, and
            //       ## and (160,120) in depth image coordinates.  Note that positive Y
            //       ## is up in skeleton space and down in image coordinates.
            //       ##
            //       pfDepthX = 0.5 + vPoint.x * ( _NUI_CAMERA_SKELETON_TO_DEPTH_IMAGE_MULTIPLIER_320x240 / vPoint.z ) / 320.0
            //       pfDepthY = 0.5 - vPoint.y * ( _NUI_CAMERA_SKELETON_TO_DEPTH_IMAGE_MULTIPLIER_320x240 / vPoint.z ) / 240.0
            //       return pfDepthX * scaleX, pfDepthY * scaleY
            //    return 0.0, 0.0

            return rPoint;
        }
Exemple #15
0
 public void TransformDepthTo3D( Byte [] data )
 {
     CoordinateMapper mapper = new CoordinateMapper( device );
     DepthImagePoint  pixels = new DepthImagePoint();
     SkeletonPoint [] points = new SkeletonPoint[ 320 * 120 ];
     var p = mapper.MapDepthPointToSkeletonPoint( DepthImageFormat.Resolution640x480Fps30,
         pixels );
 }
Exemple #16
0
        void GetCameraPoint(Skeleton first, AllFramesReadyEventArgs e)
        {
            using (DepthImageFrame depth = e.OpenDepthImageFrame())
            {
                if (depth == null ||
                    kinectSensorChooser1.Kinect == null)
                {
                    return;
                }

                //Map a joint location to a point on the depth map
                //head
                DepthImagePoint headDepthPoint =
                    depth.MapFromSkeletonPoint(first.Joints[JointType.Head].Position);
                //left hand
                DepthImagePoint leftDepthPoint =
                    depth.MapFromSkeletonPoint(first.Joints[JointType.HandLeft].Position);
                //right hand
                DepthImagePoint rightDepthPoint =
                    depth.MapFromSkeletonPoint(first.Joints[JointType.HandRight].Position);


                //Map a depth point to a point on the color image
                //head
                ColorImagePoint headColorPoint =
                    depth.MapToColorImagePoint(headDepthPoint.X, headDepthPoint.Y,
                                               ColorImageFormat.RgbResolution640x480Fps30);
                //left hand
                ColorImagePoint leftColorPoint =
                    depth.MapToColorImagePoint(leftDepthPoint.X, leftDepthPoint.Y,
                                               ColorImageFormat.RgbResolution640x480Fps30);
                //right hand
                ColorImagePoint rightColorPoint =
                    depth.MapToColorImagePoint(rightDepthPoint.X, rightDepthPoint.Y,
                                               ColorImageFormat.RgbResolution640x480Fps30);


                //Set location
                //CameraPosition(headImage, headColorPoint);
                //CameraPosition(leftEllipse, leftColorPoint);
                CameraPosition(RightHand, rightColorPoint);
                CameraPosition(LeftHand, rightColorPoint);

                #region HoverButton convertir en Check

                #region menu HoverButton

                if (stringhb.Equals("menu"))
                {
                    CheckButton(menuHbCursosProgramacionExtension, RightHand);
                    CheckButton(menuHbCarrerasProfesionales, RightHand);
                    CheckButton(menuHbConsultoriaInvestigacionAplicada, RightHand);
                    CheckButton(menuHbContactenos, RightHand);
                }
                #endregion

                #region cpe HoverButton
                if (stringhb.Equals("cpe"))
                {
                    CheckButton(cpeHbComunicacionesInalambricas, RightHand);
                    CheckButton(cpeHbAdministracionLinux, RightHand);
                    CheckButton(cpeHbTelefoniaIpAsterisk, RightHand);
                    CheckButton(cpeHbVozTelefoniaIp, RightHand);
                }
                #endregion

                #region flecha HoverButton
                if (flecha == true)
                {
                    CheckButton(flechaHbIzquierda, RightHand);
                }

                #endregion

                #endregion
            }
        }
Exemple #17
0
 private bool HasDepth(DepthImagePoint point)
 {
     return point.Depth > 0;
 }
        void sensor_AllFramesReady(object sender, AllFramesReadyEventArgs e)
        {
            using (DepthImageFrame depthFrame = e.OpenDepthImageFrame())
            {
                if (depthFrame == null)
                {
                    return;
                }

                int minDepth = 850;
                int maxDepth = 4000;

                System.Drawing.Bitmap outBmp = new System.Drawing.Bitmap(160, 160);
                BitmapSource          depthBitmapSource;
                BitmapSource          processedBitmapSource;

                //Get the position of interest on the depthmap from skeletal tracking
                DepthImagePoint rightHandPoint = jointTracker.GetJointPosition(kinectSensorChooser.Kinect, e, JointType.HandRight);


                if (jointTracker.JointDetected == true)
                {
                    textResult.Text = "Right hand is being tracked";

                    int rightHandDepth = rightHandPoint.Depth;
                    if (rightHandDepth < 850)
                    {
                        minDepth = 850;
                        maxDepth = 1500;
                    }
                    else
                    {
                        minDepth = rightHandDepth - 75;
                        maxDepth = rightHandDepth + 75;
                    }

                    depthBitmapSource = sliceDepthImage(depthFrame, minDepth, maxDepth);

                    //Create a bitmap from the depth information
                    System.Drawing.Bitmap depthBmp = depthBitmapSource.ToBitmap();

                    //Aforge performs image processing here.
                    outBmp = imageProcessor.ProcessFrame(depthBmp, rightHandPoint.X, rightHandPoint.Y);
                }
                else
                {
                    textResult.Text = "No hand detected";

                    //depthBitmapSource = sliceDepthImage(depthFrame, 850, 1500);

                    System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(outBmp);
                    g.Clear(System.Drawing.Color.Black);
                }

                //Create a bitmapsource to show the processed image
                processedBitmapSource = outBmp.ToBitmapSource();

                //Display the images
                procImageDisplay.Source = processedBitmapSource;
            }
        }
Exemple #19
0
        void sensor_AllFramesReady(object sender, AllFramesReadyEventArgs e)
        {
            if (testnumber == 1)
            {
                getSelectedFiles();
                startDrag();
                testnumber = 0;
            }

            drag();

            if (closing)
            {
                return;
            }

            //Get a skeleton
            Skeleton first = GetFirstSkeleton(e);

            if (first == null)
            {
                return;
            }

            //set scaled position
            //ScalePosition(headImage, first.Joints[JointType.Head]);
            //ScalePosition(leftEllipse, first.Joints[JointType.HandLeft]);
            ScalePosition(Cursor, first.Joints[JointType.HandRight]);
            using (DepthImageFrame depth = e.OpenDepthImageFrame())
            {
                if (depth == null ||
                    kinectSensorChooser1.Kinect == null)
                {
                    return;
                }
                float[]         skeletonValues      = new float[9];
                DepthImagePoint leftSkeletalPoint2  = depth.MapFromSkeletonPoint(first.Joints[JointType.HandLeft].Position);
                DepthImagePoint rightSkeletalPoint2 = depth.MapFromSkeletonPoint(first.Joints[JointType.HandRight].Position);
                DepthImagePoint headDepthPoint      = depth.MapFromSkeletonPoint(first.Joints[JointType.Head].Position);
                skeletonValues[0] = leftSkeletalPoint2.X;
                skeletonValues[1] = leftSkeletalPoint2.Y;
                skeletonValues[2] = leftSkeletalPoint2.Depth;
                skeletonValues[3] = rightSkeletalPoint2.X;
                skeletonValues[4] = rightSkeletalPoint2.Y;
                skeletonValues[5] = rightSkeletalPoint2.Depth;
                skeletonValues[6] = headDepthPoint.X;
                skeletonValues[7] = headDepthPoint.Y;
                skeletonValues[8] = headDepthPoint.Depth;
                storedSkeletonValues.Add(skeletonValues);
                System.Windows.Forms.Cursor.Position = new System.Drawing.Point((int)RHPos[0], (int)RHPos[1]);

                if (!actionWait)
                {
                    if (!selectActivated)
                    {
                        CheckSwipe(e);
                    }
                    CheckStatic(e);
                }
                if (lassoFilesDragging)
                {
                    //Console.WriteLine("lassofiles dragging");
                    //myimg_MouseMove();
                    CursorInCommitBoxZone();
                    CursorInTrashZone();
                }
                if (selectActivated)
                {
                    mouseLeftDown();
                }
            }
            GetCameraPoint(first, e);

            /*if (selectActivated)
             * {
             *  FollowPointer();
             * }
             * */

            FollowPointer();
        }
        public void Evaluate(int SpreadMax)
        {
            if (this.FInvalidateConnect)
            {
                if (runtime != null)
                {
                    this.runtime.SkeletonFrameReady -= SkeletonReady;
                }

                if (this.FInRuntime.PluginIO.IsConnected)
                {
                    //Cache runtime node
                    this.runtime = this.FInRuntime[0];

                    if (runtime != null)
                    {
                        this.FInRuntime[0].SkeletonFrameReady += SkeletonReady;
                    }
                }

                this.FInvalidateConnect = false;
            }

            if (this.FInvalidate)
            {
                if (this.lastframe != null)
                {
                    List <Skeleton> skels = new List <Skeleton>();
                    float           z     = float.MaxValue;
                    int             id    = -1;

                    lock (m_lock)
                    {
                        foreach (Skeleton sk in this.lastframe)
                        {
                            if (sk.TrackingState == SkeletonTrackingState.Tracked)
                            {
                                skels.Add(sk);
                            }
                        }
                    }

                    int cnt = skels.Count;
                    this.FOutCount[0] = cnt;

                    this.FOutPosition.SliceCount           = cnt;
                    this.FOutUserIndex.SliceCount          = cnt;
                    this.FOutClipped.SliceCount            = cnt;
                    this.FOutJointPosition.SliceCount      = cnt * 20;
                    this.FOutJointColorPosition.SliceCount = cnt * 20;
                    this.FOutJointDepthPosition.SliceCount = cnt * 20;
                    this.FOutJointState.SliceCount         = cnt * 20;
                    this.FOutJointID.SliceCount            = cnt * 20;
                    this.FOutJointOrientation.SliceCount   = cnt * 20;
                    this.FOutJointWOrientation.SliceCount  = cnt * 20;
                    this.FOutJointTo.SliceCount            = cnt * 20;
                    this.FOutJointFrom.SliceCount          = cnt * 20;
                    this.FOutFrameNumber[0] = this.frameid;


                    int jc = 0;
                    for (int i = 0; i < cnt; i++)
                    {
                        Skeleton sk = skels[i];
                        this.FOutPosition[i]  = new Vector3(sk.Position.X, sk.Position.Y, sk.Position.Z);
                        this.FOutUserIndex[i] = sk.TrackingId;

                        Vector4 clip = Vector4.Zero;
                        clip.X = Convert.ToSingle(sk.ClippedEdges.HasFlag(FrameEdges.Left));
                        clip.Y = Convert.ToSingle(sk.ClippedEdges.HasFlag(FrameEdges.Right));
                        clip.Z = Convert.ToSingle(sk.ClippedEdges.HasFlag(FrameEdges.Top));
                        clip.W = Convert.ToSingle(sk.ClippedEdges.HasFlag(FrameEdges.Bottom));

                        this.FOutClipped[i] = clip;

                        foreach (Joint joint in sk.Joints)
                        {
                            this.FOutJointFrom[jc] = sk.BoneOrientations[joint.JointType].StartJoint.ToString();
                            this.FOutJointTo[jc]   = sk.BoneOrientations[joint.JointType].EndJoint.ToString();
                            BoneRotation bo  = sk.BoneOrientations[joint.JointType].HierarchicalRotation;
                            BoneRotation bow = sk.BoneOrientations[joint.JointType].AbsoluteRotation;
                            this.FOutJointID[jc]       = joint.JointType.ToString();
                            this.FOutJointPosition[jc] = new Vector3(joint.Position.X, joint.Position.Y, joint.Position.Z);

                            ColorImagePoint cp = this.runtime.Runtime.MapSkeletonPointToColor(joint.Position, ColorImageFormat.RgbResolution640x480Fps30);
                            this.FOutJointColorPosition[jc] = new Vector2(cp.X, cp.Y);
                            DepthImagePoint dp = this.runtime.Runtime.MapSkeletonPointToDepth(joint.Position, DepthImageFormat.Resolution320x240Fps30);
                            this.FOutJointDepthPosition[jc] = new Vector4(dp.X, dp.Y, dp.Depth, dp.PlayerIndex);

                            this.FOutJointOrientation[jc]  = new Quaternion(bo.Quaternion.X, bo.Quaternion.Y, bo.Quaternion.Z, bo.Quaternion.W);
                            this.FOutJointWOrientation[jc] = new Quaternion(bow.Quaternion.X, bow.Quaternion.Y, bow.Quaternion.Z, bow.Quaternion.W);
                            this.FOutJointState[jc]        = joint.TrackingState.ToString();
                            jc++;
                        }
                    }
                }
                else
                {
                    this.FOutCount[0]                      = 0;
                    this.FOutPosition.SliceCount           = 0;
                    this.FOutUserIndex.SliceCount          = 0;
                    this.FOutJointID.SliceCount            = 0;
                    this.FOutJointPosition.SliceCount      = 0;
                    this.FOutJointState.SliceCount         = 0;
                    this.FOutFrameNumber[0]                = 0;
                    this.FOutJointOrientation.SliceCount   = 0;
                    this.FOutJointWOrientation.SliceCount  = 0;
                    this.FOutJointTo.SliceCount            = 0;
                    this.FOutJointFrom.SliceCount          = 0;
                    this.FOutJointColorPosition.SliceCount = 0;
                    this.FOutJointDepthPosition.SliceCount = 0;
                }
                this.FInvalidate = false;
            }
        }
Exemple #21
0
        private IEnumerable<DepthImagePoint> MooreNeighbourhood(DepthImagePoint center, DepthImagePoint start)
        {
            var x = start.X;
            var y = start.Y;
            for (var i = 0; i < 8; i++)
            {
                // Circle the center point
                var dx = x - center.X;
                var dy = y - center.Y;
                if (dx + dy != 0) x -= dy;
                if (dx - dy != 0) y += dx;

                // Skip pixels outside the image boundaries
                if (0 <= x && x < Width && 0 <= y && y < Height)
                {
                    yield return DepthPointAt(x, y);
                }
            }
        }
        internal void OnFrameReady(KinectSensor kinectSensor, ColorImageFormat colorImageFormat, byte[] colorImage, DepthImageFormat depthImageFormat, DepthImagePixel[] depthImage, DepthImagePoint[] colorMappedDepthPoints, Skeleton skeletonOfInterest = null)
        {
            this.Sensor = kinectSensor;

            if (this.ColorImageFormat != colorImageFormat)
            {
                this.ColorImageFormat = colorImageFormat;
            }

            if (this.DepthImageFormat != depthImageFormat)
            {
                this.DepthImageFormat = depthImageFormat;
            }
            this._colorMappedDepthPoints = colorMappedDepthPoints;
            OnFrameReadyOverride(kinectSensor, colorImageFormat, colorImage, depthImageFormat, depthImage, skeletonOfInterest);
        }
 public void Update(DepthImagePoint point, double ratioX = 1.0, double ratioY = 1.0)
 {
     Update(point.X * ratioX, point.Y * ratioY);
 }
        /// <summary>
        /// Updates the face tracking information for this skeleton
        /// </summary>
        protected override void OnFrameReadyOverride(KinectSensor kinectSensor, ColorImageFormat colorImageFormat, byte[] colorImage, DepthImageFormat depthImageFormat, DepthImagePixel[] depthImage, Skeleton skeletonOfInterest = null)
        {
            if (skeletonOfInterest == null || skeletonOfInterest.TrackingState != SkeletonTrackingState.Tracked)
            {
                // nothing to do with an untracked skeleton.
                return;
            }

            var mapper = kinectSensor.CoordinateMapper;

            var depthWidth = kinectSensor.DepthStream.FrameWidth;

            var headJoint = skeletonOfInterest.Joints[JointType.Head];
            var neckJoint = skeletonOfInterest.Joints[JointType.ShoulderCenter];

            _headPoint = mapper.MapSkeletonPointToDepthPoint(headJoint.Position, depthImageFormat);
            _neckPoint = mapper.MapSkeletonPointToDepthPoint(neckJoint.Position, depthImageFormat);

            _headPoint.X = depthWidth - _headPoint.X;
            _neckPoint.X = depthWidth - _neckPoint.X;

            //VerifyFaceTracker(kinectSensor);

            //BackgroundWorker worker = new BackgroundWorker();

            //worker.DoWork += (s, e) =>
            //    {
                    //if (this.faceTracker != null)
                    //{

                    //    var shortImage = Helpers.ConvertDepthImagePixelToShort(depthImage);
                    //    FaceTrackFrame frame = this.faceTracker.Track(
                    //        colorImageFormat, colorImage, depthImageFormat, shortImage, skeletonOfInterest);

                    //    UpdateFrame(frame);
                    //}

            //    };

            //worker.RunWorkerCompleted += (s, e) =>
            //    {
            //    };

            //worker.RunWorkerAsync();
        }
        private void ReconhecerDistancia(DepthImageFrame quadro, byte[] bytesImagem, int maxDistancia)
        {
            if (quadro == null || bytesImagem == null)
                return;
            
                using (quadro)
                {
                    DepthImagePixel[] imagemProfundidade = new DepthImagePixel[quadro.PixelDataLength];
                    quadro.CopyDepthImagePixelDataTo(imagemProfundidade);

                    DepthImagePoint[] pontosImagemProfundidade = new DepthImagePoint[640 * 480];

                    Kinect.CoordinateMapper
                            .MapColorFrameToDepthFrame(Kinect.ColorStream.Format,
                                                       Kinect.DepthStream.Format, imagemProfundidade,
                                                       pontosImagemProfundidade);

                    for (int i = 0; i < pontosImagemProfundidade.Length; i++)
                    {
                        var point = pontosImagemProfundidade[i];
                        if (point.Depth < maxDistancia && KinectSensor.IsKnownPoint(point))
                        {
                            var pixelDataIndex = i * 4;
                            byte maiorValorCor =
                            Math.Max(bytesImagem[pixelDataIndex],
                            Math.Max(bytesImagem[pixelDataIndex + 1],
                            bytesImagem[pixelDataIndex + 2]));
                            bytesImagem[pixelDataIndex] = maiorValorCor;
                            bytesImagem[pixelDataIndex + 1] = maiorValorCor;
                            bytesImagem[pixelDataIndex + 2] = maiorValorCor;
                        }
                    }
                }
        }
 protected void HitTest(object sender,SkeletonFrameReadyEventArgs e)
 {
     if(IsEnabled)
         using(SkeletonFrame skeletonFrame=e.OpenSkeletonFrame())
             if(skeletonFrame!=null){
                 Skeleton[] skeletons=new Skeleton[skeletonFrame.SkeletonArrayLength];
                 skeletonFrame.CopySkeletonDataTo(skeletons);
                 Skeleton firstTrackedSkeleton=null;
                 foreach(Skeleton skel in skeletons)
                     if(skel.TrackingState==SkeletonTrackingState.Tracked){
      								firstTrackedSkeleton=skel;
                         break;
                     }
                 if(firstTrackedSkeleton==null){
                     IsTracking=false;
                     IsHitting=false;
                     return;
                 }
                 int hittingJointCount=0;
                 JointType firstHittingJoint=JointType.Head;
                 DepthImagePoint firstHittingPoint=new DepthImagePoint();
                 foreach(JointType joint in Joints){
                     var jointPoint=sensor.CoordinateMapper.MapSkeletonPointToDepthPoint(firstTrackedSkeleton.Joints[joint].Position,DepthImageFormat.Resolution640x480Fps30);
                     var HitTestResult=jointPoint.X>=SliderBounds.Left&&jointPoint.X<=SliderBounds.Right&&jointPoint.Y>=SliderBounds.Top&&jointPoint.Y<=SliderBounds.Bottom;
                     if(HitTestResult){
                         if(hittingJointCount==0){
                             firstHittingJoint=joint;
                             firstHittingPoint=jointPoint;
                         }
                         hittingJointCount++;
                     }
                 }
                 if(hittingJointCount>0&&!IsHitting){
                     IsHitting=true;
                     OnHitting(new JointHittingEventArgs(firstHittingJoint));
                 }else if(hittingJointCount==0&&IsHitting){
                     IsHitting=false;
                     OnLeave();
                 }
                 if(IsHitting){
                     if(Orientation==Orientation.Horizontal){
                         var sliderValue=((firstHittingPoint.X-SliderBounds.Left)/SliderBounds.Width)*Maximum;
                         Value=(int)sliderValue;
                     }else{
                         var sliderValue=((SliderBounds.Height-firstHittingPoint.Y+SliderBounds.Top)/SliderBounds.Height)*Maximum;
                         Value=(int)sliderValue;
                     }
                 }
             }
     return;
 }
Exemple #27
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        /// 
        void ProcSide(DepthImagePoint hand, DepthImagePoint Elbow, DepthImagePoint Shoulder, Hand obj, String name)
        {
            double UpArm = Math.Sqrt(((Elbow.X - Shoulder.X) * (Elbow.X - Shoulder.X)) + ((Elbow.Y - Shoulder.Y) * (Elbow.Y - Shoulder.Y)) + ((Elbow.Depth - Shoulder.Depth) * (Elbow.Depth - Shoulder.Depth)));
             double forArmD = (Elbow.Depth - hand.Depth);
             //(hand.Y < (.8 * Elbow.Y) || Elbow.Y < (Shoulder.Y + (UpArm / 2)))
             //Console.Write(" {0}, {1}, {2}\n", hand.Depth > Elbow.Depth * 0.92, hand.Depth, Elbow.Depth);
             if (inMenu == true)
             {

             if (hand.X <= 400 && hand.X >= 100 && hand.Y <= 400 && hand.Y >= 300)
             {
                 menuTimer++;
                 if (menuTimer >= 100)
                 {
                     inMenu = false;
                 }
             }
             else if (hand.X <= 720 && hand.X >= 420 && hand.Y <= 400 && hand.Y >= 300)
             {
                 menuTimer++;
                 if (menuTimer >= 100)
                 {
                     exiting = true;
                 }
             }
             else
             {

             }
             }
             else
             {
             if (hand.X <= Shoulder.X + 50 && hand.X >= Shoulder.X - 50
                 && hand.Y <= Shoulder.Y + 50 && hand.Y >= Shoulder.Y - 50
                 && hand.Depth <= Shoulder.Depth + 50 && hand.Depth >= Shoulder.Depth - 50) {
                     inMenu = true;
             }
             else if (/*(hand.Depth > Elbow.Depth * 0.92) /*&& (hand.Y < (1.3 * Elbow.Y))*/ Shoulder.Depth >= (hand.Depth + 250))
             {
                 if (Shoulder.Depth >= (hand.Depth + 325))
                 {
                     obj.pressed = true;
                 }
                 else
                 {
                     obj.pressed = false;
                 }
             }
             else
             {
                 //Console.Write("{0} Rest\n", name);
             }
             //Console.Write("UpArm: {0}, ForArmD: {1}, Y: {2}\n", UpArm, forArmD, hand.Y);
             }
        }
        private SkeletonPoint? GetExtremeBodyPoint(DepthImageFrame Dif, bool highest)
        {
            Skeleton skeleton = getCurrentSkeleton();
            if (skeleton != null)
            {
                if (skeleton.Joints[JointType.Head].TrackingState != JointTrackingState.Tracked)
                {
                    return null;
                }
                int skeletonIndex = -1;
                for (int i = 0; i < _skeletons.Count(); i++)
                {
                    if (_skeletons[i].TrackingId == _id)
                    {
                        skeletonIndex = i + 1;
                        break;
                    }
                }

                for (int i = highest ? 0 : _depthPixelData.Count() - 1; highest ? i < _depthPixelData.Count():i >= 0;)
                {

                    short pixel = _depthPixelData[i];

                    if ((pixel & DepthImageFrame.PlayerIndexBitmask) == skeletonIndex)
                    {
                        DepthImagePoint dip = new DepthImagePoint();
                        dip.X = (i % Dif.Width);
                        dip.Y = (i / Dif.Width);
                        dip.Depth = pixel >> DepthImageFrame.PlayerIndexBitmaskWidth;
                        return _kinectSensor.CoordinateMapper.MapDepthPointToSkeletonPoint(DepthImageFormat.Resolution640x480Fps30, dip);
                    }
                    if (highest)
                    {
                        i++;
                    }
                    else
                    {
                        i--;
                    }
                }
            }
            return null;
        }
Exemple #29
0
        /// <summary>
        /// Callback to help with mapping depth pixel to color pixel data. Uses Kinect sensor's MapDepthToColorImagePoint to 
        /// do the conversion
        /// </summary>
        /// <returns>
        /// The depth to color callback.
        /// </returns>
        private int DepthToColorCallback(
            uint depthFrameWidth,
            uint depthFrameHeight,
            uint colorFrameWidth,
            uint colorFrameHeight,
            float zoomFactor,
            Point viewOffset,
            int depthX,
            int depthY,
            ushort depthZ,
            out int colorX,
            out int colorY)
        {
            int retCode = 0;
            colorX = 0;
            colorY = 0;

            if (this.sensor != null)
            {
                var colorPoint = new ColorImagePoint();
                try
                {
                    DepthImagePoint depthImagePoint = new DepthImagePoint()
                    {
                        X = depthX,
                        Y = depthY,
                        Depth = depthZ,
                    };

                    colorPoint = this.sensor.CoordinateMapper.MapDepthPointToColorPoint(
                        this.sensor.DepthStream.Format,
                        depthImagePoint,
                        this.sensor.ColorStream.Format);
                }
                catch (InvalidOperationException e)
                {
                    string traceStr = string.Format(
                        CultureInfo.CurrentCulture,
                        "Exception on MapDepthToColorImagePoint while translating depth point({0},{1},{2}). Exception={3}",
                        depthX,
                        depthY,
                        depthZ,
                        e.Message);
                    Trace.WriteLineIf(this.traceLevel >= TraceLevel.Error, traceStr, TraceCategory);

                    retCode = -1;
                }

                colorX = colorPoint.X;
                colorY = colorPoint.Y;
            }
            else
            {
                retCode = -1;
            }

            return retCode;
        }
Exemple #30
0
 public void updateHand(DepthImagePoint newP)
 {
     P = newP;
      m_position.X = P.X;
      m_position.Y = P.Y;
 }
        private void ReconhecerProfundidade(byte[] bytesImagem, int distanciaMaxima, DepthImagePixel[] imagemProfundidade)
        {
            DepthImagePoint[] pontosImagemProfundidade = new DepthImagePoint[640 * 480];
            kinect.CoordinateMapper.MapColorFrameToDepthFrame(kinect.ColorStream.Format, kinect.DepthStream.Format, imagemProfundidade, pontosImagemProfundidade);

            for (int i = 0; i < pontosImagemProfundidade.Length; i++)
            {
                var point = pontosImagemProfundidade[i];
                if (point.Depth < distanciaMaxima && KinectSensor.IsKnownPoint(point))
                {
                    var pixelDataIndex = i * 4;

                    byte maiorValorCor = Math.Max(bytesImagem[pixelDataIndex], Math.Max(bytesImagem[pixelDataIndex + 1], bytesImagem[pixelDataIndex + 2]));

                    bytesImagem[pixelDataIndex] = maiorValorCor;
                    bytesImagem[pixelDataIndex + 1] = maiorValorCor;
                    bytesImagem[pixelDataIndex + 2] = maiorValorCor;
                }
            }
        }
    public void setJoints(AllFramesReadyEventArgs e, Skeleton skeleton)
    {
        using (DepthImageFrame depth = e.OpenDepthImageFrame())
        {
            if (depth != null)
            {
                //Map a joint location to a point on the depth map
                lastHead = currHead;
                lastNeck = currNeck;
                lastSpine = currSpine;
                lastHipCenter = currHipCenter;

                lastLeftHand = currLeftHand;
                lastLeftWrist = currLeftWrist;
                lastLeftElbow = currLeftElbow;
                lastLeftShoulder = currLeftShoulder;

                lastRightHand = currRightHand;
                lastRightWrist = currRightWrist;
                lastRightElbow = currRightElbow;
                lastRightShoulder = currRightShoulder;

                currHead = depth.MapFromSkeletonPoint(skeleton.Joints[JointType.Head].Position);
                currNeck = depth.MapFromSkeletonPoint(skeleton.Joints[JointType.ShoulderCenter].Position);
                currSpine = depth.MapFromSkeletonPoint(skeleton.Joints[JointType.Spine].Position);
                currHipCenter = depth.MapFromSkeletonPoint(skeleton.Joints[JointType.HipCenter].Position);

                currLeftHand = depth.MapFromSkeletonPoint(skeleton.Joints[JointType.HandLeft].Position);
                currLeftWrist = depth.MapFromSkeletonPoint(skeleton.Joints[JointType.WristLeft].Position);
                currLeftElbow = depth.MapFromSkeletonPoint(skeleton.Joints[JointType.ElbowLeft].Position);
                currLeftShoulder = depth.MapFromSkeletonPoint(skeleton.Joints[JointType.ShoulderLeft].Position);

                currRightHand = depth.MapFromSkeletonPoint(skeleton.Joints[JointType.HandRight].Position);
                currRightWrist = depth.MapFromSkeletonPoint(skeleton.Joints[JointType.WristRight].Position);
                currRightElbow = depth.MapFromSkeletonPoint(skeleton.Joints[JointType.ElbowRight].Position);
                currRightShoulder = depth.MapFromSkeletonPoint(skeleton.Joints[JointType.ShoulderRight].Position);
            }
        }
    }
Exemple #33
0
 public static DepthImagePoint Midpoint(DepthImagePoint p1, DepthImagePoint p2)
 {
     return new DepthImagePoint {
     X = (p1.X + p2.X) / 2,
     Y = (p1.Y + p2.Y) / 2,
     Depth = (p1.Depth + p2.Depth) / 2
       };
 }
 public static double GetBodySegmentAngle(DepthImagePoint j1, DepthImagePoint j2, DepthImagePoint j3)
 {
     return Vector3.angleBetween(new Vector3(j1.X, j1.Y, 0), new Vector3(j2.X, j2.Y, 0), new Vector3(j3.X, j3.Y, 0));
 }
Exemple #35
0
 public HandInputEvent(DepthImagePoint leftHand, DepthImagePoint rightHand)
 {
     LeftHand = leftHand;
       RightHand = rightHand;
 }
Exemple #36
0
        private Point SkeletonPointToScreen(SkeletonPoint skelpoint)
        {
            DepthImagePoint depthPoint = this.sensor.CoordinateMapper.MapSkeletonPointToDepthPoint(skelpoint, DepthImageFormat.Resolution640x480Fps30);

            return(new Point(depthPoint.X, depthPoint.Y));
        }