美文网首页
OpenCV 模版匹配

OpenCV 模版匹配

作者: 守候_小7爺 | 来源:发表于2018-05-03 09:57 被阅读0次

    Mat mCameraMat = inputFrame.rgba();

    // Create the result matrix

    int result_cols = mCameraMat.cols() - mTemplateMat.cols() + 1;

    int result_rows = mCameraMat.rows() - mTemplateMat.rows() + 1;

    Log.d(TAG, " mCameraMat cols " + mCameraMat.cols());

    Log.d(TAG, " mCameraMat rows " + mCameraMat.rows());

    Log.d(TAG, " mTemplateMat cols " + mTemplateMat.cols());

    Log.d(TAG, " mTemplateMat rows " + mTemplateMat.rows());

    Mat result = new Mat(result_rows, result_cols, CvType.CV_32F);

              // Do the Matching and Normalize

    Imgproc.matchTemplate(mCameraMat, mTemplateMat, result, match_method);

    Core.normalize(result, result, 0, 1, Core.NORM_MINMAX, -1, new Mat());

              // Localizing the best match with minMaxLoc

    Core.MinMaxLocResult mmr = Core.minMaxLoc(result);

    Point matchLoc;

    if (match_method == Imgproc.TM_SQDIFF || match_method == Imgproc.TM_SQDIFF_NORMED) {

        matchLoc = mmr.minLoc;

      } else {

      matchLoc = mmr.maxLoc;

    }

    Rect roi = new Rect((int) matchLoc.x, (int) matchLoc.y, mTemplateMat.cols(), mTemplateMat.rows());

    Imgproc.rectangle(mCameraMat, new Point(roi.x, roi.y), new Point(roi.width - 2, roi.height - 2), new Scalar(255, 0, 0, 255), 2);

    return mCameraMat;

    相关文章

      网友评论

          本文标题:OpenCV 模版匹配

          本文链接:https://www.haomeiwen.com/subject/vuyzjttx.html