public IEnumerable <Match> FindMatches(IPattern Template, double Similarity) { using var result = new DisposableMat(); // max is used for tmccoeff Imgproc.MatchTemplate(Mat, (Template as DroidCvPattern)?.Mat, result.Mat, Imgproc.TmCcoeffNormed); Imgproc.Threshold(result.Mat, result.Mat, 0.1, 1, Imgproc.ThreshTozero); while (true) { using var minMaxLocResult = Core.MinMaxLoc(result.Mat); var score = minMaxLocResult.MaxVal; if (score >= Similarity) { var loc = minMaxLocResult.MaxLoc; var region = new Region((int)loc.X, (int)loc.Y, Template.Width, Template.Height); yield return(new Match(region, score)); using var mask = new DisposableMat(); // Flood fill eliminates the problem of nearby points to a high similarity point also having high similarity const double floodFillDiff = 0.05; Imgproc.FloodFill(result.Mat, mask.Mat, loc, new Scalar(0), new Rect(), new Scalar(floodFillDiff), new Scalar(floodFillDiff), 0); } else { break; } } }
public IPattern Crop(Region Region) { Region = new Region(0, 0, Width, Height) .Clip(Region); var rect = new Rect(Region.X, Region.Y, Region.W, Region.H); var result = new Mat(Mat, rect); return(new DroidCvPattern(result)); }
public IPattern Crop(Region Region) { var rect = new Rect(Region.X, Region.Y, Region.W, Region.H); if (rect.X + rect.Width > Width) { rect.X = Width - rect.Width; } if (rect.Y + rect.Height > Height) { rect.Y = Height - rect.Height; } var result = new Mat(Mat, rect); return(new DroidCvPattern(result)); }