当前位置: 首页>>代码示例>>Java>>正文


Java Imgproc.matchTemplate方法代码示例

本文整理汇总了Java中org.opencv.imgproc.Imgproc.matchTemplate方法的典型用法代码示例。如果您正苦于以下问题:Java Imgproc.matchTemplate方法的具体用法?Java Imgproc.matchTemplate怎么用?Java Imgproc.matchTemplate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.opencv.imgproc.Imgproc的用法示例。


在下文中一共展示了Imgproc.matchTemplate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: match

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
public MatchResult match(Mat scene, Mat templ, Method method, Mat img) {
	
	int result_cols = scene.cols() - templ.cols() + 1;
	int result_rows = scene.rows() - templ.rows() + 1;
	Mat result = new Mat(result_rows, result_cols, CV_32FC1);
	Imgproc.matchTemplate(scene, templ, result, method.ordinal());
	//Core.normalize(result, result, 0, 1, 32,-1,new Mat());
		
	MinMaxLocResult mmr = Core.minMaxLoc(result);

	
	Point matchLoc;
	double maxVal;
	if (method.ordinal() == Imgproc.TM_SQDIFF
	        || method.ordinal() == Imgproc.TM_SQDIFF_NORMED) {
	    
		matchLoc = mmr.minLoc;
		maxVal = mmr.minVal;
	}
	else {
	    matchLoc = mmr.maxLoc;
	    maxVal = mmr.maxVal;
	}
	
	MatchResult currResult = new MatchResult(matchLoc.x +(templ.cols()/2),matchLoc.y +(templ.rows()/2),0,maxVal);
	return currResult;
}
 
开发者ID:Flash3388,项目名称:FlashLib,代码行数:28,代码来源:CvTemplateMatcher.java

示例2: findImage

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
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);
}
 
开发者ID:mcdcorp,项目名称:opentest,代码行数:59,代码来源:ImageFinder.java

示例3: matchTemplate

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
public static Mat matchTemplate(Mat img, Mat temp, int match_method) {
    int result_cols = img.cols() - temp.cols() + 1;
    int result_rows = img.rows() - temp.rows() + 1;
    Mat result = new Mat(result_rows, result_cols, CvType.CV_32FC1);
    Imgproc.matchTemplate(img, temp, result, match_method);
    return result;
}
 
开发者ID:hyb1996,项目名称:Auto.js,代码行数:8,代码来源:TemplateMatching.java


注:本文中的org.opencv.imgproc.Imgproc.matchTemplate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。