/// <param name="small">Small image that will be searched</param> /// <param name="big">Big image that small image will be searched in</param> /// <param name="returnCenter">middle of small bmp</param> public static MatchPoint Find(Mat small, Mat big, bool returnCenter = true) { MatchPoint result; using (Mat mresult = Match(small, big)) { Cv2.MinMaxLoc(mresult, out var minVal, out var maxVal, out var minLoc, out var maxLoc); //For SquareDifference and SquareDifferenceNormed, the best matches are lower values. //For all the other methods, the higher the better var matchVal = MatchingMethod == TemplateMatchModes.SqDiff || MatchingMethod == TemplateMatchModes.SqDiffNormed ? minVal : maxVal; var matchLoc = MatchingMethod == TemplateMatchModes.SqDiff || MatchingMethod == TemplateMatchModes.SqDiffNormed ? minLoc : maxLoc; if (returnCenter) { matchLoc.X += small.Width / 2; matchLoc.Y += small.Height / 2; } result = new MatchPoint(matchLoc, matchVal); } return(result); }
public static MatchPoint Find(Bitmap small, Bitmap big, bool returnCenter = true) { MatchPoint result; using (Mat sm = BitmapToMat(small)) using (Mat bm = BitmapToMat(big)) using (Mat Mresult = Match(sm, bm)) { double minVal, maxVal, MatchVal; OpenCV.Net.Point minLoc, maxLoc, MatchLoc; CV.MinMaxLoc(Mresult, out minVal, out maxVal, out minLoc, out maxLoc); //For SquareDifference and SquareDifferenceNormed, the best matches are lower values. //For all the other methods, the higher the better MatchVal = (MatchingMethod == Methods.SquareDifference || MatchingMethod == Methods.SquareDifferenceNormed) ? minVal : maxVal; MatchLoc = (MatchingMethod == Methods.SquareDifference || MatchingMethod == Methods.SquareDifferenceNormed) ? minLoc : maxLoc; if (returnCenter) { MatchLoc.X += small.Width / 2; MatchLoc.Y += small.Height / 2; } result = new MatchPoint(MatchLoc, MatchVal); } return result; }
public static MatchPoint Find(Bitmap small, Bitmap big, bool returnCenter = true) { MatchPoint result; using (Mat sm = BitmapToMat(small)) using (Mat bm = BitmapToMat(big)) using (Mat Mresult = Match(sm, bm)) { double minVal, maxVal, MatchVal; OpenCV.Net.Point minLoc, maxLoc, MatchLoc; CV.MinMaxLoc(Mresult, out minVal, out maxVal, out minLoc, out maxLoc); //For SquareDifference and SquareDifferenceNormed, the best matches are lower values. //For all the other methods, the higher the better MatchVal = (MatchingMethod == Methods.SquareDifference || MatchingMethod == Methods.SquareDifferenceNormed) ? minVal : maxVal; MatchLoc = (MatchingMethod == Methods.SquareDifference || MatchingMethod == Methods.SquareDifferenceNormed) ? minLoc : maxLoc; if (returnCenter) { MatchLoc.X += small.Width / 2; MatchLoc.Y += small.Height / 2; } result = new MatchPoint(MatchLoc, MatchVal); } return(result); }