这是我的代码:
private void button3_Click(object sender, EventArgs e)
{
string strFileName = string.Empty;
OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog() == DialogResult.OK)
{
Image<Bgr, byte> img1 = new Image<Bgr, byte>(ofd.FileName);
pictureBox1.Image = img1.ToBitmap();
Image<Gray, Byte> gray1 = img1.Convert<Gray, Byte>().PyrUp().PyrDown();
CircleF[] circles = gray1.HoughCircles(
new Gray(150),
new Gray(100),
2,
10,
0,
0)[0];
Image<Bgr, byte> imageCircles = img1.CopyBlank();
foreach (CircleF circle in circles)
{
imageCircles.Draw(circle, new Bgr(Color.Yellow), 5);
}
pictureBox4.Image = imageCircles.ToBitmap();
}
}
我的参数设置正确吗?有什么我不能正确理解的吗? 谢谢!
答案 0 :(得分:0)
EmguCV包装了OpenCV的内容,因此您可以通过查看OpenCV Doku来获取有关如何使用Emgu方法的信息。 Here是他解释的Hough变换(可能是参数计数或顺序变化但在大多数情况下参数名称匹配。在解释点4(继续应用Hough Circle变换:)你得到所有参数解释:
dp = 1: The inverse ratio of resolution
min_dist = src_gray.rows/8: Minimum distance between detected centers
param_1 = 200: Upper threshold for the internal Canny edge detector
param_2 = 100*: Threshold for center detection.
min_radius = 0: Minimum radio to be detected. If unknown, put zero as default.
max_radius = 0: Maximum radius to be detected. If unknown, put zero as default
根据Emgu Doku使用这些值:
cannyThreshold
Type: TColor
The higher threshold of the two passed to Canny edge detector (the lower one will be twice smaller).
accumulatorThreshold
Type: TColor
Accumulator threshold at the center detection stage. The smaller it is, the more false circles may be detected. Circles, corresponding to the larger accumulator values, will be returned first
dp
Type: SystemDouble
Resolution of the accumulator used to detect centers of the circles. For example, if it is 1, the accumulator will have the same resolution as the input image, if it is 2 - accumulator will have twice smaller width and height, etc
minDist
Type: SystemDouble
Minimum distance between centers of the detected circles. If the parameter is too small, multiple neighbor circles may be falsely detected in addition to a true one. If it is too large, some circles may be missed
minRadius (Optional)
Type: SystemInt32
Minimal radius of the circles to search for
maxRadius (Optional)
Type: SystemInt32
Maximal radius of the circles to search for
因此,请尝试使用更高的accumulatorThreshold(如150或180),因为您的圈子非常明显。在大图像上,较高的dp也会有所帮助,减少您的等待时间。
你的dp是10(我认为它意味着检测到的中心之间的10pixils)根据你的图像大小,只需要更高的数字。 OpenCV示例使用高度为8的图像。
minRadius为0应该没问题,因为你的图像只显示大(黄色)圆圈。
最大无线电也应该取决于您的图像尺寸 - 这将删除较低图像部分中的那些非常大的圆圈。
只需尝试5%的图像高度作为minRadius,将90%作为maxRadius - 或者只使用滑块和应用按钮自行尝试