phase 12
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
"""Registration for preprocessing stages: frame extraction, scene filter."""
|
||||
"""Registration for preprocessing stages: frame extraction, scene filter, image preprocessing."""
|
||||
|
||||
from detect.stages.base import StageDefinition, StageIO, StageConfigField, register_stage
|
||||
from ._serializers import serialize_frames, deserialize_frames
|
||||
@@ -25,6 +25,17 @@ def _deser_filter(data: dict, job_id: str) -> dict:
|
||||
return {"_filtered_sequences": data["filtered_frame_sequences"]}
|
||||
|
||||
|
||||
def _ser_preprocess(state: dict, job_id: str) -> dict:
|
||||
# Preprocessed crops are numpy arrays — regenerable from frames + boxes + config
|
||||
crops = state.get("preprocessed_crops", {})
|
||||
return {"crop_keys": list(crops.keys()), "count": len(crops)}
|
||||
|
||||
|
||||
def _deser_preprocess(data: dict, job_id: str) -> dict:
|
||||
# Crops are regenerable — no need to restore from checkpoint
|
||||
return {"preprocessed_crops": {}}
|
||||
|
||||
|
||||
def register():
|
||||
extract = StageDefinition(
|
||||
name="extract_frames",
|
||||
@@ -55,3 +66,22 @@ def register():
|
||||
deserialize_fn=_deser_filter,
|
||||
)
|
||||
register_stage(scene_filter)
|
||||
|
||||
preprocess = StageDefinition(
|
||||
name="preprocess",
|
||||
label="Preprocess",
|
||||
description="Image preprocessing on detected regions before OCR",
|
||||
category="preprocessing",
|
||||
io=StageIO(
|
||||
reads=["filtered_frames", "boxes_by_frame"],
|
||||
writes=["preprocessed_crops"],
|
||||
),
|
||||
config_fields=[
|
||||
StageConfigField("contrast", "bool", True, "CLAHE contrast enhancement"),
|
||||
StageConfigField("deskew", "bool", False, "Correct slight rotation"),
|
||||
StageConfigField("binarize", "bool", False, "Otsu binarization"),
|
||||
],
|
||||
serialize_fn=_ser_preprocess,
|
||||
deserialize_fn=_deser_preprocess,
|
||||
)
|
||||
register_stage(preprocess)
|
||||
|
||||
Reference in New Issue
Block a user