保存圆的边框OpenCV Android

保存圆的边框OpenCV Android,android,opencv,mobile,crop,Android,Opencv,Mobile,Crop,您好,我正在使用Houghcirle检测圆我还制作了一个边界框来显示圆的轮廓我现在要做的是抓取边界框内的图像并将其保存到文件或位图中 这是我的密码 // accumulator value double dp = 1; // minimum distance between the center coordinates of detected circles in pixels double minD

您好,我正在使用Houghcirle检测圆我还制作了一个边界框来显示圆的轮廓我现在要做的是抓取边界框内的图像并将其保存到文件或位图中

这是我的密码

            // accumulator value
            double dp = 1;
            // minimum distance between the center coordinates of detected circles in pixels
            double minDist = gray_src.rows() / 8;
            // min and max radiuis
            int minRadius = 0, maxRadius = 500;
            //Last two
            double iCanny = 100, accum = 25;

            // create a Mat object to store the circles detected
            Mat circles = new Mat();

            // find the circle in the image
            Imgproc.HoughCircles(outlineThick, circles, Imgproc.CV_HOUGH_GRADIENT, dp, minDist, iCanny, accum, minRadius, maxRadius);

            // get the number of circles detected
            int numberOfCircles = (circles.rows() == 0) ? 0 : circles.

            // int x = (int) circleCoordinates[0], y = (int) circleCoordinates[1];
            Point pt;


            Rect[] roiArray = new Rect[numberOfCircles];
            for (int i = 0; i < numberOfCircles; i++) {
                double circleCoordinates[] = circles.get(0, i);
                pt = new Point(Math.round(circleCoordinates[0]), Math.round(circleCoordinates[1]));
                //circle's outline
                int radius = (int) Math.round(circleCoordinates[2]);
                Log.d("LOG", "Circle: X=" + Double.toString(circleCoordinates[0]) + " Y=" + Double.toString(circleCoordinates[1]));
                Imgproc.circle(src, pt, radius, new Scalar(0, 255, 0), 2, 8, 0);
                Imgproc.rectangle(src, new Point(pt.x - (radius + 1), pt.y - (radius + 1)), new Point(pt.x + (radius + 1), pt.y + (radius + 1)), new Scalar(255, 0, 0), 2);
                Rect roi = new Rect(new Point(pt.x - (radius + 1), pt.y - (radius + 1)), new Point(pt.x + (radius + 1), pt.y + (radius + 1)));
                roiArray[i] = roi;
            }
//累加器值
双dp=1;
//检测到的圆的中心坐标之间的最小距离(像素)
double Minist=gray_src.rows()/8;
//最小和最大半径
int minRadius=0,maxRadius=500;
//最后两个
双iCanny=100,累计=25;
//创建Mat对象以存储检测到的圆
垫圆=新垫();
//在图中找到圆圈
Imgproc.HoughCircles(大纲图、圆、Imgproc.CV_-HOUGH_梯度、dp、Minist、iCanny、accum、minRadius、maxRadius);
//获取检测到的圆数
int numberOfCircles=(circles.rows()==0)?0:圆圈。
//int x=(int)圈坐标[0],y=(int)圈坐标[1];
点pt;
Rect[]roiArray=新Rect[numberOfCircles];
for(int i=0;i
我尝试过使用类似的东西:
submat(dst,mask)但保存图像时得到的只是全尺寸图像,而不是裁剪版本


任何帮助都将不胜感激

Submat也接受Rect。用那个!谢谢Miki,使用submat对我有用