23 lines
856 B
Python
23 lines
856 B
Python
import json
|
|
from pathlib import Path
|
|
import geometric_grouper
|
|
|
|
regions_file = Path(r"output\20260614_225443\pages\page_004.regions.json")
|
|
img_file = Path(r"output\20260614_225443\pages\page_004.png")
|
|
|
|
with open(regions_file, encoding='utf-8') as f:
|
|
regions = json.load(f)["regions"]
|
|
|
|
valid_regions = [r for r in regions if r["type"] not in ("header", "footer", "page_number")]
|
|
|
|
articles = geometric_grouper.group_surya_regions_geometrically(valid_regions, img_path=str(img_file))
|
|
|
|
print(f"Total articles identified: {len(articles)}")
|
|
for a in articles:
|
|
print(f" Article {a['article_id']}: {len(a['member_regions'])} regions, bbox {a['bbox']}")
|
|
for rid in a['member_regions']:
|
|
r = next((x for x in regions if x['id'] == rid), None)
|
|
if r:
|
|
print(f" Region {rid}: type={r['type']:15s} bbox={r['bbox']}")
|
|
print()
|