sundeep-news-scan/scratch_test_grouper.py

18 lines
681 B
Python

import json
from pathlib import Path
import geometric_grouper
regions_file = Path("output/20260614_124012/pages/page_004.regions.json")
img_file = Path("output/20260614_124012/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']}, grouped_by={a['grouped_by']}")