Check PAGE line outlines while moving the cut in the offline batch reviewer, version 0.4.2
f65b994 verified Download evaluate_points.py from foliokestrel/folio-fold: direct link, hf CLI and curl.
- Browser
- Download file 760 Bytes
-
https://huggingface.co/foliokestrel/folio-fold/resolve/main/evaluate_points.py
- Command line
-
hf download hf://foliokestrel/folio-fold/evaluate_points.py
-
curl -L -o evaluate_points.py https://huggingface.co/foliokestrel/folio-fold/resolve/main/evaluate_points.py
760 Bytes
| """Read normalized baseline or contour coordinates from PAGE XML.""" | |
| import math | |
| def points(node,width,height,polygon): | |
| if node is None: | |
| return "missing",() | |
| try: | |
| pts=[tuple(map(float,p.split(","))) for p in node.get("points","").split()] | |
| if any(len(p)!=2 or not all(map(math.isfinite,p)) for p in pts): | |
| return "invalid",() | |
| except ValueError: | |
| return "invalid",() | |
| if any(not (0<=x<=width and 0<=y<=height) for x,y in pts): | |
| return "outside",() | |
| if len(set(pts))<(3 if polygon else 2): | |
| return "degenerate",() | |
| if polygon and sum(a[0]*b[1]-a[1]*b[0] for a,b in zip(pts,pts[1:]+pts[:1]))==0: | |
| return "zero_area",() | |
| return "usable",tuple((x/width,y/height) for x,y in pts) | |