2013-05-04 49 views
1

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

由于

回答

2

Unfurtunately在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可变玩,你可以检测椭圆呢!

希望它有帮助。