ObjectDetector
Detector for archaeological objects using color-based segmentation.
Constructor
Detection configuration parameters. Controls target color, area filters, morphological kernel, and HSV tolerances.
When
True, intermediate processing images (HSV conversion, masks, contours) are stored in each DetectionResult.processing_steps dictionary.detect
Detect objects in a single in-memory image.
Input image in BGR format as a NumPy array.
Name identifier used in logging and stored in the returned
DetectionResult.DetectionResult
detect_from_path
Detect objects in an image loaded from disk.
Path to the image file to process.
DetectionResult
process_directory
Process all images in a directory and collect results in a BatchDetectionResult.
Directory containing input images. All supported image formats are processed.
Optional directory for saving intermediate processing images. When
None and save_intermediate=True, intermediate images are stored in memory only.BatchDetectionResult
DetectionConfig
Pydantic model holding all detection parameters. All fields have defaults so you only need to supply values you want to change.
Target color in hex format (e.g.
"#A98876"). The detector converts this to HSV and applies hue_offset, saturation_offset, and value_offset tolerances to produce the color range mask.Minimum contour area in pixels. Contours smaller than this are discarded. Must be ≥ 1.
Maximum contour area in pixels. Contours larger than this are discarded. Must be ≥ 1.
Size of the morphological operation kernel used for closing and opening passes on the mask.
Tolerance for the hue channel in HSV color matching. Range 0–90.
Tolerance for the saturation channel in HSV color matching. Range 0–127.
Tolerance for the value channel in HSV color matching. Range 0–127.
Return types
DetectionResult
Result of running detection on a single image. This is a dataclass (not a Pydantic model).
Name of the processed image (the file stem when loaded from disk).
List of filtered OpenCV contour arrays that passed the area constraints.
List of detected objects with extracted features.
Intermediate images keyed by step name (e.g.
"01_hsv", "02_mask_initial"). Populated only when save_intermediate=True.Read-only property. Number of detected objects (
len(objects)).BatchDetectionResult
Aggregated results from processing a directory of images. This is a dataclass.
One
DetectionResult per successfully processed image.Read-only property. Sum of detected objects across all images.
Read-only property. Number of images in
results.DetectedObject
A single detected object with its metadata and extracted features.
Filename of the source image.
Zero-based index of this contour within the image. Must be ≥ 0.
Extracted geometric features for this object.
