private List <Body> CreateBodies(TimeSpan frameRelativeTime, List <Head> validatedHeads) { _stopwatch.Restart(); Dictionary <Head, int> identifiedHeadsWithLabels = BodyUtils.IdentifyHeads(validatedHeads); var bodies = new List <Body>(); foreach (var identifiedHead in identifiedHeadsWithLabels) { Stopwatch stopwatchBody = new Stopwatch(); stopwatchBody.Start(); Body body; int bodyId = identifiedHead.Value; Head head = identifiedHead.Key; if (bodyId == -1) { GlobVar.MaxBodyCount++; int newBodyId = GlobVar.MaxBodyCount; body = new Body(newBodyId, frameRelativeTime); body.AddHead(head); bodies.Add(body); BodyUtils.AddBodyRegions(GeodesicUtils.GeodesicGraph, head, body); } else { // Attribute head with average centerpoint in from the last // frames. head.AvgCenterPoint = BodyUtils.GetAverageHeadLocationLastFrames(bodyId); if (Logger.ShowHeadAvgCenterPoint) { GraphicsUtils.DrawPoint(head.AvgCenterPoint); } body = new Body(bodyId, frameRelativeTime); body.AddHead(head); bodies.Add(body); BodyUtils.AddBodyRegions(GeodesicUtils.GeodesicGraph, head, body); } Logger.Draw(body); EnergyUtils.CalculateBodyMechanicalEnergy(body); } if (Logger.LogTimeCreateBodies) { _stopwatch.Stop(); Console.WriteLine("CreateBodies: {0}", _stopwatch.ElapsedMilliseconds); } return(bodies); }
private List <Head> DetectHeads(CameraSpacePoint[] noiseFilteredFrame) { _stopwatch.Restart(); var haarDetector = new HaarDetector(noiseFilteredFrame); List <int> headCandidatesHaar = haarDetector.GetHeadCandidates(); if (Logger.LogTimeHaar) { _stopwatch.Stop(); Console.WriteLine("Haar: {0}", _stopwatch.ElapsedMilliseconds); } _stopwatch.Restart(); var candidatesHighestConnectingPoints = new List <int>(); for (int i = 0; i < headCandidatesHaar.Count; i++) { if (Logger.ShowCandidateHeadpixel) { GraphicsUtils.DrawPoint(headCandidatesHaar[i]); } int headCandidateIndex = headCandidatesHaar[i]; if (headCandidateIndex != -1) { int highestPointIndex = ClassificationUtils.GetHighestConnectingPoint(headCandidateIndex, Thresholds.ClassificationHighestPointSearchDepth); candidatesHighestConnectingPoints.Add(highestPointIndex); if (Logger.ShowTopHeadpixel) { GraphicsUtils.DrawPoint(highestPointIndex); } } } var groupedHighestIndexes = ClassificationUtils.GroupCandidatesHighestPoints(candidatesHighestConnectingPoints, Thresholds.ClassificationHighestPointGroupingDistance); List <Head> validatedCandidateHeads = ValidateCandidateHeads(groupedHighestIndexes); GlobVar.ValidatedCandidateHeads = validatedCandidateHeads; if (Logger.LogTimeClassificationValidation) { _stopwatch.Stop(); Console.WriteLine("ClassificationValidation: {0}", _stopwatch.ElapsedMilliseconds); } return(validatedCandidateHeads); }
/// <summary> /// Draw bodyelements in detection frame for debugging purposes. /// </summary> public static void Draw(Body body) { if (ShowHandCenterPoint) { Hand firstHand = body.Hands[0]; if (firstHand != null) { GraphicsUtils.DrawPoint(firstHand.CenterPoint); } Hand secondHand = body.Hands[1]; if (secondHand != null) { GraphicsUtils.DrawPoint(secondHand.CenterPoint); } } if (ShowHandAvgPoint) { Hand firstHand = body.Hands[0]; if (firstHand != null && !float.IsNaN(firstHand.AvgCenterPointLastFrames.Z)) { GraphicsUtils.DrawPoint(firstHand.AvgCenterPointLastFrames); } Hand secondHand = body.Hands[1]; if (secondHand != null && !float.IsNaN(secondHand.AvgCenterPointLastFrames.Z)) { GraphicsUtils.DrawPoint(secondHand.AvgCenterPointLastFrames); } } if (ShowTorsoCenterPoint) { if (body.Torso != null && !float.IsNaN(body.Torso.CenterPoint.Z)) { GraphicsUtils.DrawPoint(body.Torso.CenterPoint); } } if (ShowTorsoAvgCenterPoint) { if (body.Torso != null && !float.IsNaN(body.Torso.AvgCenterPoint.Z)) { GraphicsUtils.DrawPoint(body.Torso.AvgCenterPoint); } } if (ShowHeadCenterPoint) { GraphicsUtils.DrawPoint(body.Head.CenterPoint); } }
private static Dictionary <int, CameraSpacePoint> GetAvgLocationsRecentHeadsFromIds(List <int> recentBodyIds) { var avgLocationsRecentHeads = new Dictionary <int, CameraSpacePoint>(); foreach (var bodyId in recentBodyIds) { avgLocationsRecentHeads.Add(bodyId, GetAverageHeadLocationLastTenFrames(bodyId)); if (Logger.ShowHeadAvgCenterLastTenFrames) { if (!float.IsNaN(GetAverageHeadLocationLastTenFrames(bodyId).Z)) { GraphicsUtils.DrawPoint(GetAverageHeadLocationLastTenFrames(bodyId)); } } } return(avgLocationsRecentHeads); }
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); }