/// <summary> /// Takes a circle in image space and returns a cooresponding ellipse in image space. /// This is an ill posed problem. The center is respected but the radius could be taken /// anywhere around the circle in image space, and that yields different radii in world space. /// We use the point along the X axis as the radius. /// </summary> public Ellipse GetEllipseFromCircle(PointF center, float radius, out PointF radiusLeftInImage, out PointF radiusRightInImage) { radiusLeftInImage = new PointF(center.X - radius, center.Y); radiusRightInImage = new PointF(center.X + radius, center.Y); if (calibratorType == CalibratorType.Line) { return(new Ellipse(center, radius, radius, 0)); } // Rebuild the world-space circle based on center and radius alone. PointF centerInWorld = GetPoint(center); // Estimate the radius in world space. // Get scalar will assumes reference direction to be X-axis in image space. float radiusInWorld = GetScalar(radius); // Get the intersection points of a horizontal diameter. // This is used to draw a line from the center to the outline of the ellipse in perspective. radiusLeftInImage = GetImagePoint(centerInWorld.Translate(-radiusInWorld, 0)); radiusRightInImage = GetImagePoint(centerInWorld.Translate(radiusInWorld, 0)); // Get the square enclosing the circle for mapping. PointF a = GetImagePoint(centerInWorld.Translate(-radiusInWorld, -radiusInWorld)); PointF b = GetImagePoint(centerInWorld.Translate(radiusInWorld, -radiusInWorld)); PointF c = GetImagePoint(centerInWorld.Translate(radiusInWorld, radiusInWorld)); PointF d = GetImagePoint(centerInWorld.Translate(-radiusInWorld, radiusInWorld)); QuadrilateralF quadImage = new QuadrilateralF(a, b, c, d); ProjectiveMapping mapping = new ProjectiveMapping(); mapping.Update(QuadrilateralF.CenteredUnitSquare, quadImage); return(mapping.Ellipse()); }
/// <summary> /// Takes a circle in real world coordinates and returns a cooresponding ellipse in image coordinates. /// </summary> public Ellipse GetEllipseFromCircle(PointF center, float radius) { if (calibratorType == CalibratorType.Line) { return(new Ellipse(GetImagePoint(center), GetImageScalar(radius), GetImageScalar(radius), 0)); } // Get the square enclosing the circle for mapping. PointF a = GetImagePoint(center.Translate(-radius, -radius)); PointF b = GetImagePoint(center.Translate(radius, -radius)); PointF c = GetImagePoint(center.Translate(radius, radius)); PointF d = GetImagePoint(center.Translate(-radius, radius)); QuadrilateralF quadImage = new QuadrilateralF(a, b, c, d); ProjectiveMapping mapping = new ProjectiveMapping(); mapping.Update(QuadrilateralF.CenteredUnitSquare, quadImage); return(mapping.Ellipse()); }