GoldenBear23's picture
Deploy snapshot for HF Space
71efe81
Raw
History Blame Contribute Delete
1.41 kB
#!/usr/bin/env python3
"""
Registry of shape-specific secondary validators, dispatched by the
exemplar's classified shape_type (see classical_cv_detector.classify_shape).
Shape types with no registered validator (square, triangle, pentagon,
polygon, unknown) fall back to geometry+OCR only, same as Phase 1.
"""
from . import circle, diamond, hexagon
VALIDATORS = {
"diamond": diamond.validate,
"circle": circle.validate,
"hexagon": hexagon.validate,
}
# Shape types with a full tuned detect_page(bgr, tile_size, overlap, ocr_upscale)
# pipeline (contour + text-first passes, recall-tuned thresholds). Dispatched
# by classical_cv_detector.detect_page() to run shape-detection first, ahead
# of the generic exemplar mask/template-correlation pass. Shape types without
# an entry here (circle, square, triangle, pentagon, polygon, unknown) have no
# such pipeline and rely on mask/template matching + get_validator() alone.
PIPELINES = {
"diamond": diamond.detect_page,
"hexagon": hexagon.detect_page,
}
def get_validator(shape_type: str):
"""Return the validate(binary_orig, binary_cleaned, cx, cy, r) -> bool function for shape_type, or None."""
return VALIDATORS.get(shape_type)
def get_pipeline(shape_type: str):
"""Return the detect_page(bgr, tile_size, overlap, ocr_upscale) -> list[dict] function for shape_type, or None."""
return PIPELINES.get(shape_type)