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


Java Imgproc.TM_SQDIFF_NORMED属性代码示例

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


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

示例1: match

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,代码行数:27,代码来源:CvTemplateMatcher.java

示例2: getBestMatched

public static Pair<Point, Double> getBestMatched(Mat tmResult, int matchMethod, float threshold) {
    TimingLogger logger = new TimingLogger(LOG_TAG, "best_matched_point");
    // FIXME: 2017/11/26 正交化?
    //   Core.normalize(tmResult, tmResult, 0, 1, Core.NORM_MINMAX, -1, new Mat());
    Core.MinMaxLocResult mmr = Core.minMaxLoc(tmResult);
    logger.addSplit("minMaxLoc");
    double value;
    Point pos;
    if (matchMethod == Imgproc.TM_SQDIFF || matchMethod == Imgproc.TM_SQDIFF_NORMED) {
        pos = mmr.minLoc;
        value = -mmr.minVal;
    } else {
        pos = mmr.maxLoc;
        value = mmr.maxVal;
    }
    logger.addSplit("value:" + value);
    logger.dumpToLog();
    return new Pair<>(pos, value);
}
 
开发者ID:hyb1996,项目名称:Auto.js,代码行数:19,代码来源:TemplateMatching.java

示例3: 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);
}
 
开发者ID:mcdcorp,项目名称:opentest,代码行数:58,代码来源:ImageFinder.java


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