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要怎么使用

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