85岁欧尼酱 2022-05-12 09:41 采纳率: 38.9%
浏览 86
已结题

boundingRect的使用


    public void imgCapture(){
        
        Mat gray = new Mat();
        Imgproc.cvtColor(mat, gray, Imgproc.COLOR_BGR2GRAY);
        
        Mat blur = new Mat();
        Imgproc.blur(gray, blur, new Size(5, 5));
       
        Mat thresh = new Mat();
        Imgproc.threshold(blur, thresh, 0, 255, Imgproc.THRESH_BINARY | Imgproc.THRESH_TRIANGLE);
        List<MatOfPoint> contours = new ArrayList<>();
        Mat hierarchy = new Mat();
        Imgproc.findContours(thresh, contours, hierarchy, Imgproc.RETR_TREE, Imgproc.CHAIN_APPROX_SIMPLE);

        double area_max = 0;
        MatOfPoint _cnt = null;
        for (MatOfPoint cnt:contours) {
            double area = Imgproc.contourArea(cnt);
            if (area > area_max){
                area_max = area;
                _cnt = cnt;
            }
        }
        if (_cnt == null)
            return;
        Rect rect = Imgproc.boundingRect(_cnt);
        
        mat = new Mat(mat, rect);
    }

这个方法是用来裁剪图像的吗还有那个boundingRect要怎么使用

  • 写回答

1条回答 默认 最新

  • 不会写代码的猴子 Android领域优质创作者 2022-05-12 10:14
    关注

    boundingRect计算轮廓的垂直边界最小矩形(矩形是与图像上下边界平行的)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 5月22日
  • 已采纳回答 5月14日
  • 创建了问题 5月12日

悬赏问题

  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler