File size: 1,097 Bytes
dac3297
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import json, glob, re, sys, warnings
warnings.filterwarnings('ignore')
sys.path.insert(0, '.')
from pathlib import Path
import analyze_blueprint as ab

pdf_path = Path(r'..\raw_pdfs\355 E 86th St Mechanical 100% CD Set_flattened.pdf')
out = Path('output')

with open('output/355 E 86th St Mechanical 100% CD Set_flattened_schedule_cache.json') as f:
    sched = json.load(f)
known = list(sched.keys())
tag_colors = ab._build_color_map(sorted(known))

files = sorted(glob.glob('output/floor_*_detections.json'))
for fp in files:
    m = re.match(r'.*floor_(\d+)_(.+)_detections\.json', fp)
    if not m: continue
    page_num = int(m.group(1)); floor_name = m.group(2)
    out_png = out / f'floor_{page_num:03d}_{floor_name}_annotated.png'
    if out_png.exists():
        continue
    with open(fp) as f:
        data = json.load(f)
    hits = [ab.TagHit(**h) for h in data['hits']]
    color_img = ab._render_page(pdf_path, page_num - 1, 300)
    ab.annotate_and_save(floor_name.replace('_', ' '), page_num, color_img, hits, out, tag_colors)
    print(f'annotated: {out_png.name}')
print('done')