【发布时间】:2020-04-22 08:39:47
【问题描述】:
我正在尝试检测、定位和拾取蓝色弹珠。 我的项目的目的是一次只检测 1 个弹珠。 对于我的检测,我使用的是 OpenCV 的 HoughCircles 函数。我想代码只给我第一个检测到的圆的 X 和 Y 位置。
这是我为此使用的代码:
vector<Vec3f> circles;
HoughCircles(OutputImage, circles, HOUGH_GRADIENT, 1,
OutputImage.rows / rows, //change to detect circles that are closer to eachother
para1, para2, minRad, maxRad); //chang last to parameters to detect larger or smaller circles
for (size_t i = 0; i < circles.size(); i++)
{
Vec3i c = circles[i];
Point center = Point(c[0], c[1]);
// circle center
circle(imgHSV, center, 1, Scalar(0, 255, 0), 3, LINE_AA);
// circle outline
int radius = c[2];
circle(imgHSV, center, radius, Scalar(255, 0, 0), 3, LINE_AA);
cout << "The center of the detection is located at pixel: " << Point(c[0], c[1]) << endl;
x = c[0];
y = c[1];
}
但是,这仍然会检测所有圆圈并打印出所有圆圈的 X、Y 信息。
我尝试在 for 循环中将 circles.size() 更改为 1 但这给了我以下错误:
Expression: vector subscript out of range
这里有人能帮助我吗,这是我的第一个 OpenCV 应用程序,如果我误解了,请见谅。
如果您需要我的完整代码,请随时询问。
【问题讨论】: