主要方法如下:
/// <summary>
///
/// </summary>
/// <param name="img1">大图</param>
/// <param name="img2">小图</param>
/// <returns></returns>
public static Rectangle GetMatchPos(string img1, string img2)
{
Mat Src = CvInvoke.Imread(img1, ImreadModes.Grayscale);
Mat Template = CvInvoke.Imread(img2, ImreadModes.Grayscale);
Mat MatchResult = new Mat();//匹配结果
CvInvoke.MatchTemplate(Src, Template, MatchResult, Emgu.CV.CvEnum.TemplateMatchingType.CcorrNormed);//使用相关系数法匹配
Point max_loc = new Point();
Point min_loc = new Point();
double max = 0, min = 0;
CvInvoke.MinMaxLoc(MatchResult, ref min, ref max, ref min_loc, ref max_loc);//获得极值信息
return new Rectangle(max_loc, Template.Size);
}
C#加载emgu动态库,可以在右键引用,点击管理NuGet程序包,在新窗口中搜索 “emgu.cv”,安装即可,项目会自动引用!