本文整理匯總了Java中org.opencv.imgproc.Imgproc.TM_CCOEFF_NORMED屬性的典型用法代碼示例。如果您正苦於以下問題:Java Imgproc.TM_CCOEFF_NORMED屬性的具體用法?Java Imgproc.TM_CCOEFF_NORMED怎麽用?Java Imgproc.TM_CCOEFF_NORMED使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類org.opencv.imgproc.Imgproc
的用法示例。
在下文中一共展示了Imgproc.TM_CCOEFF_NORMED屬性的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: findImage
private ImageFinderResult findImage(Mat sourceMat, Mat templateMat, double desiredAccuracy) {
if (sourceMat.width() < templateMat.width() || sourceMat.height() < templateMat.height()) {
throw new UnsupportedOperationException("The template image is larger than the source image. Ensure that the width and/or height of the image you are trying to find do not exceed the dimensions of the source image.");
}
Mat result = new Mat(sourceMat.rows() - templateMat.rows() + 1, sourceMat.rows() - templateMat.rows() + 1, CvType.CV_32FC1);
int intMatchingMethod;
switch (this.matchingMethod) {
case MM_CORELLATION_COEFF:
intMatchingMethod = Imgproc.TM_CCOEFF_NORMED;
break;
case MM_CROSS_CORELLATION:
intMatchingMethod = Imgproc.TM_CCORR_NORMED;
break;
default:
intMatchingMethod = Imgproc.TM_SQDIFF_NORMED;
}
Imgproc.matchTemplate(sourceMat, templateMat, result, intMatchingMethod);
MinMaxLocResult minMaxLocRes = Core.minMaxLoc(result);
double accuracy = 0;
Point location = null;
if (this.matchingMethod == MatchingMethod.MM_SQUARE_DIFFERENCE) {
accuracy = 1 - minMaxLocRes.minVal;
location = minMaxLocRes.minLoc;
} else {
accuracy = minMaxLocRes.maxVal;
location = minMaxLocRes.maxLoc;
}
if (accuracy < desiredAccuracy) {
throw new ImageNotFoundException(
String.format(
"Failed to find template image in the source image. The accuracy was %.2f and the desired accuracy was %.2f",
accuracy,
desiredAccuracy),
new Rectangle((int) location.x, (int) location.y, templateMat.width(), templateMat.height()),
accuracy);
}
if (!minMaxLocResultIsValid(minMaxLocRes)) {
throw new ImageNotFoundException(
"Image find result (MinMaxLocResult) was invalid. This usually happens when the source image is covered in one solid color.",
null,
null);
}
Rectangle foundRect = new Rectangle(
(int) location.x,
(int) location.y,
templateMat.width(),
templateMat.height());
return new ImageFinderResult(foundRect, accuracy);
}