【发布时间】:2014-05-25 21:14:35
【问题描述】:
我有下面的图片,我真正想要检测的是框上方的圆圈,每个框的左上角都有字母。但结果是它还检测到了其他一些圆圈。我不知道为什么。
我要检测的图像:
结果如下:
如您所见,它有时可以找到字母为圆圈,也可以找到乐高上的圆圈。这是我的代码:
Mat source = Highgui.imread("testar.jpg", Highgui.CV_LOAD_IMAGE_COLOR);
Mat destination = new Mat(source.rows(), source.cols(), source.type());
Imgproc.cvtColor(source, destination, Imgproc.COLOR_RGB2GRAY);
Imgproc.GaussianBlur(destination, destination, new Size(3,3),0,0);
Mat circles = new Mat();
Imgproc.HoughCircles(destination, circles, Imgproc.CV_HOUGH_GRADIENT, 1, 20, 10, 20, 7, 13);
int radius;
Point pt;
for (int x = 0; x < circles.cols(); x++) {
double vCircle[] = circles.get(0,x);
if (vCircle == null)
break;
pt = new Point(Math.round(vCircle[0]), Math.round(vCircle[1]));
radius = (int)Math.round(vCircle[2]);
// draw the found circle
Core.circle(destination, pt, radius, new Scalar(0,255,255), 3);
Core.circle(destination, pt, 3, new Scalar(255,255,255), 3);
}
Highgui.imwrite("foundCircles.jpg", destination);
【问题讨论】:
-
霍夫圆函数似乎按预期工作,因为它在您的测试图像中找到的只是某种圆。如果您对要查找的圆圈类型有更高的了解,则应该使用它(测试圆圈内有哪些颜色,圆圈内是否还有其他字母等)。
-
抱歉,我觉得这很准确
标签: java opencv hough-transform