Download src/linedet/det_overlay.py from treoa/turkic-ocr-code: direct link, hf CLI and curl.
- Browser
- Download file 1.06 kB
-
https://huggingface.co/treoa/turkic-ocr-code/resolve/main/src/linedet/det_overlay.py
- Command line
-
hf download hf://treoa/turkic-ocr-code/src/linedet/det_overlay.py
-
curl -L -o det_overlay.py https://huggingface.co/treoa/turkic-ocr-code/resolve/main/src/linedet/det_overlay.py
1.06 kB
| """Draw the line polygons, boxes and baselines of two pages on the page image (quality check of the converted annotations).""" | |
| import json | |
| import sys | |
| import cv2 | |
| import numpy as np | |
| from .common import DATA, read_manifest | |
| from .det_prep import baseline_from_polygon | |
| def main(split, idx, out): | |
| rows = read_manifest("%s/data/processed/r5_linedet_det/school2/pages_school_%s.tsv" % (DATA, split)) | |
| r = rows[int(idx)] | |
| im = cv2.imread(r["image"]) | |
| polys = json.loads(r["polys_json"]) | |
| for p in polys: | |
| pts = np.array(p, dtype=np.int32).reshape(-1, 1, 2) | |
| cv2.polylines(im, [pts], True, (0, 0, 255), 1) | |
| pass | |
| for b in json.loads(r["baselines_json"]): | |
| bl = np.array(b, dtype=np.int32).reshape(-1, 1, 2) | |
| cv2.polylines(im, [bl], False, (0, 200, 0), 2) | |
| cv2.imwrite(out, im, [cv2.IMWRITE_JPEG_QUALITY, 80]) | |
| print(r["id"], im.shape, len(polys), "ref_lines:", (json.loads(r["ref_lines_json"])[:3] if r["ref_lines_json"] else None)) | |
| if __name__ == "__main__": | |
| main(sys.argv[1], sys.argv[2], sys.argv[3]) | |