Opencv for Android 之轮廓查找

 /**
     * 模板匹配
     * @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);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值