Android opencv(四)轮廓检测

本文介绍了如何在Android中使用OpenCV进行轮廓检测,重点讲解了findContours函数的用法,并展示了如何找到面积最大的轮廓以及如何绘制轮廓。内容还提及轮廓检测前提需要二值化图像。
摘要由CSDN通过智能技术生成

轮廓检测函数:
Imgproc. findContours(image, contours, hierarchy, mode, method)
通过轮廓检测找到面积最大的轮廓并绘制轮廓:

        List<MatOfPoint> contours=new ArrayList<>();
        Imgproc.findContours(blurredImage,contours,new Mat(),Imgproc.RETR_LIST,Imgproc.CHAIN_APPROX_SIMPLE);
        double maxVal = 0;
        int maxValIdx = 0;
        for (int contourIdx = 0; contourIdx < contours.size(); contourIdx++)
        {
            double contourArea = Imgproc.contourArea(contours.get(contourIdx));
            if (maxVal < contourArea)
            {
                maxVal = contourArea;
                maxValIdx = contourIdx;
            }
        }
 Mat mRgba=new Mat();
        mRgba.create(blurredImage.rows(), blurredImage.cols(), CvType.CV_8UC3);
        //绘制检测到的轮廓
         Imgproc.drawContours(mRgba, contours, maxAreaIdx, new Scalar(0,255,0), 5);
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值