File size: 1,064 Bytes
24aaa76
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"""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])