Exemplo n.º 1
0
        /// <summary>
        /// Performs body tracking on frame
        /// </summary>
        private void TrackBodies(TimeSpan frameRelativeTime, CameraSpacePoint[] noiseFilteredFrame)
        {
            var validatedHeads = DetectHeads(noiseFilteredFrame);

            _stopwatch.Restart();

            GeodesicUtils.CreateGeodesicGraph(noiseFilteredFrame);

            if (Logger.LogTimeGeodesic)
            {
                _stopwatch.Stop();
                Console.WriteLine("CreateGeodesicGraph: {0}", _stopwatch.ElapsedMilliseconds);
            }
            _stopwatch.Restart();

            var bodies = CreateBodies(frameRelativeTime, validatedHeads);

            BodiesHistory.Update(bodies);

            GlobVar.TimeStamps.Add(frameRelativeTime);
            TrackingDiagnostics.AddNewBodyFrame(bodies);
            _heatMap.AddFrame(GlobVar.HeatCanvas);
            EnergyHistory.Update(bodies);

            if (Logger.PrintFps)
            {
                var currentTime = frameRelativeTime;
                Console.WriteLine("FPS: {0}", Logger.CalculateFps(currentTime, _timestampPreviousFrame));
                _timestampPreviousFrame = currentTime;
            }
        }
        ///  <summary>
        ///     Uses Dijkstra to find the shortest geodesic path from the top of the head to the rest of the body. The body parts
        ///     torso and hands are classified as the points from the geodesic map that fall into bins with a certain distance from
        ///     the top of the head.
        /// </summary>
        /// <returns>Returns a dictionary with the heads as keys and labels as values. If head isn't identified, the label is -1</returns>
        public static void AddBodyRegions(Dictionary <int, Dictionary <int, float> > geodesicGraph, Head head, Body body)
        {
            var startIndex = head.HighestPointIndex;

            if (!geodesicGraph.ContainsKey(startIndex))
            {
                startIndex = GeodesicUtils.GetClosestValidNeighbourInGeodesicGraph(startIndex);
            }

            if (startIndex == -1)
            {
                return;
            }

            var minDistances = Dijkstra.Perform(startIndex, geodesicGraph);

            var handPoints  = new List <int>();
            var torsoPoints = new List <int>();

            foreach (var minDistance in minDistances)
            {
                if (minDistance.Value < 1.1f)
                {
                    // Include body in current heatcanvas
                    GlobVar.HeatCanvas[minDistance.Key] = body.Id;
                }
                if (minDistance.Value < 0.2f)
                {
                    if (Logger.ShowHeadRegionPixels)
                    {
                        GlobVar.GraphicsCanvas[minDistance.Key] = 255;
                    }
                    torsoPoints.Add(minDistance.Key);
                }
                else if (minDistance.Value < 0.6f && minDistance.Value > 0.2f)
                {
                    if (Logger.ShowTorsoPixels)
                    {
                        GlobVar.GraphicsCanvas[minDistance.Key] = 200;
                    }
                    torsoPoints.Add(minDistance.Key);
                }
                else if (minDistance.Value < 1.2f && minDistance.Value > 0.9f)
                {
                    if (Logger.ShowHandPixels)
                    {
                        GlobVar.GraphicsCanvas[minDistance.Key] = 150;
                    }
                    handPoints.Add(minDistance.Key);
                }
            }

            if (torsoPoints.Count > Thresholds.TorsoPointMinCount)
            {
                body.AddTorso(torsoPoints);
            }

            if (handPoints.Count > Thresholds.HandPointMinCount)
            {
                body.AddHands(handPoints);
            }
        }