RapidOCRCSharp
RapidOCRCSharp copied to clipboard
ClipperLib to Clipper2Lib
原作者已更新Clipper2Lib
private static List<Point> Unclip(List<PointF> box, float unclip_ratio) { RotatedRect clipRect = CvInvoke.MinAreaRect(box.ToArray()); if (clipRect.Size.Height < 1.001 && clipRect.Size.Width < 1.001) { return null; }
Path64 theCliperPts = new Path64();
foreach (PointF pt in box)
{
theCliperPts.Add(new Point64((int)pt.X, (int)pt.Y));
}
float area = Math.Abs(SignedPolygonArea(box.ToArray<PointF>()));
double length = LengthOfPoints(box);
double distance = area * unclip_ratio / length;
ClipperOffset co = new ClipperOffset();
co.AddPath(theCliperPts, JoinType.Round, EndType.Polygon);
Paths64 solution = new Paths64();
co.Execute(distance, solution);
if (solution.Count == 0)
{
return null;
}
List<Point> retPts = new List<Point>();
foreach (Point64 ip in solution[0])
{
retPts.Add(new Point((int)ip.X, (int)ip.Y));
}
return retPts;
}