當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。