您好我正在使用HoughCircle来检测圆圈我还创建了一个边框来显示圆圈的轮廓我现在想要做的是抓取边界框内的图像并将它们保存到文件或位图
这是我的代码
// 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;
}
我尝试过使用像submat(dst,mask);
之类的东西,但是当我保存图像时我得到的只是全尺寸图像而不是裁剪版本
非常感谢任何帮助