Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
OpenCVSharpでテンプレートマッチング(OpenCV3.0対応)
private OpenCvSharp.Point getTemplateAreaLocation(Mat matTarget, Mat matTemplate, int LocFlag) {
Mat result = new Mat(matTarget.Height - matTemplate.Height + 1, matTarget.Width - matTemplate.Width + 1, MatType.CV_8UC1);
OpenCvSharp.Point minPoint = new OpenCvSharp.Point();
OpenCvSharp.Point maxPoint = new OpenCvSharp.Point();
try {
Cv2.MatchTemplate(matTarget, matTemplate, result, TemplateMatchModes.CCoeff);
Cv2.MinMaxLoc(result, out minPoint, out maxPoint);
}
catch (OpenCvSharp.OpenCVException ee) {
System.Diagnostics.Debug.WriteLine(ee.ErrMsg);
}
if (LocFlag == 0) {
return minPoint;
}
else {
return maxPoint;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment