public void AddHead(Head head)
 {
     Head = head;
 }
        ///  <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);
            }
        }
        private static List<Head> ValidateCandidateHeads(IReadOnlyList<int> groupedHighestIndexes)
        {
            List<Head> validatedCandidateHeads = new List<Head>();

            foreach (var highestPointIndex in groupedHighestIndexes)
            {
                if (Logger.ShowTopHeadPixelAfterGrouping)
                {
                    GraphicsUtils.DrawPoint(highestPointIndex);
                }

                var headPointIndexes = ClassificationUtils.ConnectedComponentLabeling(highestPointIndex, Thresholds.ClassificationLabelingMaxPoints);

                if (Logger.ShowHeadpixelsBeforeValidation)
                {
                    foreach (var index in headPointIndexes)
                    {
                        GraphicsUtils.DrawPoint(index);
                    }
                }

                if (Validators.EvaluateSizeOfHeadRegion(headPointIndexes))
                {
                    if (Logger.ShowValidatedTopHeadpixel)
                    {
                        GraphicsUtils.DrawPoint(highestPointIndex);
                    }

                    var head = new Head(highestPointIndex);
                    var success = head.AddHeadPixels(headPointIndexes);
                    if (success != -1)
                    {
                        validatedCandidateHeads.Add(head);
                    }
                    if (Logger.ShowValidatedHeadPixels)
                    {
                        foreach (var p in head.HeadPointIndexes)
                        {
                            GraphicsUtils.DrawPoint(p);
                        }
                    }
                }
            }
            return validatedCandidateHeads;
        }
        ///  <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);
            }
        }
Beispiel #5
0
 public void AddHead(Head head)
 {
     Head = head;
 }