1

好吧,我正在使用 SimpleShapeChecker.IsCircle 方法来检测我的瞳孔。它工作得很好,但是当我看向侧面时,瞳孔会变成椭圆形/椭圆形。有没有检测椭圆的方法?或者有没有办法“放松” IsCircle() 方法?

谢谢

4

1 回答 1

2

不幸的是,在 AForge 中没有 IsOval() 函数。

但是你可以看一下形状检查器的源代码!

https://code.google.com/p/aforge/source/browse/trunk/Sources/Math/Geometry/SimpleShapeChecker.cs?r=1402

您可以查看 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 变量,您也可以检测到椭圆!

希望它有所帮助。

于 2013-05-07T12:22:12.030 回答