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); }
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); }