from parseport.tools.layout_detector import BaseLayoutDetector
from parseport.struct import ComponentBlock, ComponentType, BoundingBox
from parseport.tools.registry import register_detector
@register_detector('my-custom-detector')
class MyCustomDetector(BaseLayoutDetector):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.model = None
def _initialize(self):
"""Load models or initialize resources (called on first use)"""
self.model = load_my_model() # Your model loading logic
def predict(self, img_array: np.ndarray, page_num: int, **kwargs) -> List[ComponentBlock]:
"""Run detection on the input image"""
self._ensure_initialized() # Always call this first
# Your detection logic here
detections = self.model.detect(img_array)
# Convert detections to ComponentBlocks
components = []
for det in detections:
components.append(ComponentBlock(
type=det.type, # or TABLE, FIGURE, IMAGE
bbox=BoundingBox(
x0=det.x0, y0=det.y0,
x1=det.x1, y1=det.y1
),
page_num=page_num,
text=""
))
return components