You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

模板匹配无法获取精确匹配结果的问题求助

模板匹配无法获取精确匹配结果的问题求助

我现在在做一个简单的模板匹配,但不管怎么试都得不到正确的匹配结果。我试过不转灰度图处理,也尝试移除模板的alpha通道,但都没起到作用。甚至还试了尺度不变的匹配方法,结果还是不行。

这是我使用的模板:
模板图片

这是待匹配的目标大图:
大图图片

以下是我当前的实现代码:

public static boolean isIconPresent(String largeImagePath, String iconPath, double threshold) {
    // Load images
    Mat largeImageColor = Imgcodecs.imread(largeImagePath);
    Mat iconColor = Imgcodecs.imread(iconPath);

    if (largeImageColor.empty() || iconColor.empty()) {
        throw new IllegalArgumentException("Could not load images.");
    }

    // Convert to grayscale (optional)
    Mat largeImage = new Mat();
    Mat icon = new Mat();
    Imgproc.cvtColor(largeImageColor, largeImage, Imgproc.COLOR_BGR2GRAY);
    Imgproc.cvtColor(iconColor, icon, Imgproc.COLOR_BGR2GRAY);

    // Result matrix
    int resultCols = largeImage.cols() - icon.cols() + 1;
    int resultRows = largeImage.rows() - icon.rows() + 1;
    Mat result = new Mat(resultRows, resultCols, CvType.CV_32FC1);

    // Template matching
    Imgproc.matchTemplate(largeImage, icon, result, Imgproc.TM_CCOEFF_NORMED);

    // Get match location
    Core.MinMaxLocResult mmr = Core.minMaxLoc(result);
    Point matchLoc = mmr.maxLoc;
    double maxVal = mmr.maxVal;

    System.out.println("Match confidence: " + maxVal);
    return maxVal >= threshold;
}

有没有大佬能帮我分析下问题出在哪?或者给我一些排查的方向?

内容来源于stack exchange

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.08 07:28:08