我有一个计算圆的圆度的函数。如果结果是1.00,圆圈是完美的圆形,任何低于1.00的圆圈都表示圆形不完美。除了一个小问题之外,它运行良好,有时它将值显示为无穷大,我无法找到原因。我正在使用浮点计算它,尝试加倍,但同样的事情发生了。
以下是代码:
for (int i = 0, n = blobs.Length; i < n; i++)
{
List<IntPoint> edgePoints = bc.GetBlobsEdgePoints(blobs[i]);
List<IntPoint> hull = hullFinder.FindHull(edgePoints);
double perimeter = 0.0;
for (int j = 0; j < hull.Count - 1; j++)
{
perimeter += hull[j].DistanceTo(hull[j + 1]);
}
perimeter += hull[hull.Count - 1].DistanceTo(hull[0]);
float circularity = (float)((4 * Math.PI * blob.Area) / (Math.Pow(perimeter, 2)));
double circround = Math.Round(circularity, 3);
lblcircle.Text = circround.ToString();
}