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;
本文来自博客园,作者:一夜梦想,转载请注明原文链接:https://www.cnblogs.com/caiyingyong/p/11866158.html