Created
February 4, 2017 05:56
-
-
Save ochilab/beb2bd783556459e54e40132e4732cd1 to your computer and use it in GitHub Desktop.
OpenCVSharpでテンプレートマッチング(OpenCV3.0対応)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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