openCV-2.4.9 小图在大图中位置(初步接触openCV)

#include <QDebug>

#define log qDebug() << "[" << __FILE__ << ":" << __LINE__ << "]"


    cv::Mat resImage = cv::imread(resPath);
    cv::Mat targetImage = cv::imread(targetPath);
    if (resImage.empty() || targetImage.empty()) {
        log << "图像加载错误";
        return;
    }

    int h = targetImage.rows;
    int w = targetImage.cols;
    log << h << w;

    cv::Mat result;
    result.create(w, h, CV_32FC1);

    cv::matchTemplate(resImage, targetImage, result, cv::TM_CCOEFF_NORMED);
    
    double minVal = -1;
    double maxVal = -1;
    cv::Point minLoc;
    cv::Point maxLoc;
    cv::Point matchLoc;
    cv::minMaxLoc(result, &minVal, &maxVal, &minLoc, &maxLoc, cv::Mat());
    if (maxVal < 0.85) {
        log << "找到失败";
        return;
    }
    log << minVal;
    log << maxVal;
    log << minLoc.x << minLoc.y;
    log << maxLoc.x << maxLoc.y;    

 

posted @ 2019-11-15 14:20  一夜梦想  阅读(1240)  评论(0编辑  收藏  举报