OpenCV Template Matching Drawing Rectangle Around Match

不羁岁月 提交于 2019-12-06 09:07:46

Find the match in your mResult, paint the rect on the Input using Core.rectangle and write this into file.

// / Localizing the best match with minMaxLoc
MinMaxLocResult mmr = Core.minMaxLoc(mResult);

Point matchLoc;
if (match_method == Imgproc.TM_SQDIFF || match_method == Imgproc.TM_SQDIFF_NORMED) {
    matchLoc = mmr.minLoc;
} else {
    matchLoc = mmr.maxLoc;
}

// / Show me what you got
Core.rectangle(Input, matchLoc, new Point(matchLoc.x + templ.cols(),
        matchLoc.y + templ.rows()), new Scalar(0, 255, 0));

// Save the visualized detection.
System.out.println("Writing "+ outFile);
Highgui.imwrite(outFile, img);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!