C# OpenCvSharp 模板匹配
public static System.Drawing.Point FindPicFromImage(Mat srcMat, Mat dstMat, double threshold = 0.9)
{
OpenCvSharp.OutputArray outArray = null;
try
{
srcMat = srcMat.CvtColor(ColorConversionCodes.RGBA2RGB);
outArray = OpenCvSharp.OutputArray.Create(srcMat);
OpenCvSharp.Cv2.MatchTemplate(srcMat, dstMat, outArray, TemplateMatchModes.SqDiff);
double minValue, maxValue;
OpenCvSharp.Point location, point;
OpenCvSharp.Cv2.MinMaxLoc(OpenCvSharp.InputArray.Create(outArray.GetMat()), out minValue, out maxValue, out location, out point);
Console.WriteLine(maxValue);
if (maxValue >= threshold)
return new System.Drawing.Point(point.X, point.Y);
return System.Drawing.Point.Empty;
}
catch (Exception ex)
{
return System.Drawing.Point.Empty;
}
finally
{
}
}