1
嗯,我正在使用SimpleShapeChecker.IsCircle方法來檢測我的瞳孔。它工作得很好,但是當我向兩側看時,瞳孔變成橢圓形/橢圓形。有沒有檢測橢圓的方法?還是有辦法「放鬆」IsCircle()方法?AForge ShapeCheker.IsCircle方法
由於
嗯,我正在使用SimpleShapeChecker.IsCircle方法來檢測我的瞳孔。它工作得很好,但是當我向兩側看時,瞳孔變成橢圓形/橢圓形。有沒有檢測橢圓的方法?還是有辦法「放鬆」IsCircle()方法?AForge ShapeCheker.IsCircle方法
由於
Unfurtunately在AForge沒有IsOval()函數。
但你可以看看形狀檢查器的源代碼!
你可以看到IsCircle()函數,並修改它,看是否爲橢圓形或沒有。
這是函數:
public bool IsCircle(List<IntPoint> edgePoints, out Point center, out float radius)
{
// make sure we have at least 8 points for curcle shape
if (edgePoints.Count < 8)
{
center = new Point(0, 0);
radius = 0;
return false;
}
// get bounding rectangle of the points list
IntPoint minXY, maxXY;
PointsCloud.GetBoundingRectangle(edgePoints, out minXY, out maxXY);
// get cloud's size
IntPoint cloudSize = maxXY - minXY;
// calculate center point
center = minXY + (Point) cloudSize/2;
radius = ((float) cloudSize.X + cloudSize.Y)/4;
// calculate mean distance between provided edge points and estimated circle’s edge
float meanDistance = 0;
for (int i = 0, n = edgePoints.Count; i < n; i++)
{
meanDistance += (float) Math.Abs(center.DistanceTo(edgePoints[i]) - radius);
}
meanDistance /= edgePoints.Count;
float maxDitance = Math.Max(minAcceptableDistortion,
((float) cloudSize.X + cloudSize.Y)/2 * relativeDistortionLimit);
return (meanDistance <= maxDitance);
}
也許如果你與minAcceptableDistortion可變玩,你可以檢測橢圓呢!
希望它有幫助。