RapidOCRCSharp icon indicating copy to clipboard operation
RapidOCRCSharp copied to clipboard

ClipperLib to Clipper2Lib

Open shouhujishu opened this issue 1 year ago • 0 comments

原作者已更新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;
    }

shouhujishu avatar Jul 05 '23 14:07 shouhujishu