/** * 模板匹配 * @param dt 原图片 * @param matchMask 模板图片 * @return 返回的是匹配到的点 */ private Point templateMatching (Mat dt, Mat matchMask){ Core.MinMaxLocResult result; Mat matchResult=new Mat(); matchResult.create(new Size(dt.cols() - matchMask.cols()+1, dt.rows() - matchMask.rows()+1), CV_8UC1); //----模板匹配找四个定位点,归一化相关系数匹配法(初始数据范围太大,自己通过image watch 查看) int method = Imgproc.TM_CCOEFF_NORMED; matchTemplate(dt, matchMask, matchResult, method, new Mat()); normalize(matchResult, matchResult, 0, 1, NORM_MINMAX); //规格化 result= minMaxLoc(matchResult); Point maxloc = result.maxLoc; Point minloc = result.minLoc; Point matchloc = null; if(method == Imgproc.TM_SQDIFF || method == Imgproc.TM_SQDIFF_NORMED) { matchloc = minloc; } else { matchloc = maxloc; } Imgproc.rectangle(dt, matchloc, new Point(matchloc.x+mobanMat.cols(), matchloc.y + mobanMat.rows()), new Scalar(0, 0, 255), 2, 8, 0); LoggerUtil.logInfo(result.maxLoc.x+" "+result.maxLoc.y+" "+result.minLoc.x ); showImage(dt); return new Point(result.maxLoc.x,result.maxLoc.y); }
Opencv for Android 之轮廓查找
最新推荐文章于 2023-06-07 22:44:53 发布