|
4 | 4 | import cv2 |
5 | 5 | import numpy as np |
6 | 6 | import supervision as sv |
7 | | -from pydantic import AliasChoices, ConfigDict, Field |
| 7 | +from pydantic import AliasChoices, ConfigDict, Field, PositiveInt |
8 | 8 | from shapely.geometry import Polygon |
9 | 9 |
|
10 | 10 | from inference.core.workflows.execution_engine.entities.base import ( |
@@ -90,34 +90,32 @@ class MotionDetectionManifest(WorkflowBlockManifest): |
90 | 90 | validation_alias=AliasChoices("image", "images"), |
91 | 91 | ) |
92 | 92 |
|
93 | | - minimum_contour_area: Union[Selector(kind=[INTEGER_KIND]), int] = Field( |
| 93 | + minimum_contour_area: Union[PositiveInt, Selector(kind=[INTEGER_KIND])] = Field( |
94 | 94 | title="Minimum Contour Area", |
95 | 95 | description="Minimum area in square pixels for a motion region to be detected. Contours smaller than this threshold are filtered out to ignore noise, small shadows, or minor pixel variations. Lower values increase sensitivity but may detect more false positives (e.g., 100 for very sensitive detection, 500 for only large objects). Default is 200 square pixels.", |
96 | | - gt=0, |
97 | 96 | examples=[200, 100, 500], |
98 | 97 | default=200, |
99 | 98 | ) |
100 | 99 |
|
101 | | - morphological_kernel_size: Union[Selector(kind=[INTEGER_KIND]), int] = Field( |
102 | | - title="Morphological Kernel Size", |
103 | | - description="Size of the morphological kernel in pixels used to combine nearby motion regions and filter noise. Larger values merge more distant motion regions into single contours but may also merge separate objects. Smaller values preserve more detail but may leave fragmented detections. The kernel uses an elliptical shape. Default is 3 pixels.", |
104 | | - gt=0, |
105 | | - examples=[3, 5, 7], |
106 | | - default=3, |
| 100 | + morphological_kernel_size: Union[PositiveInt, Selector(kind=[INTEGER_KIND])] = ( |
| 101 | + Field( |
| 102 | + title="Morphological Kernel Size", |
| 103 | + description="Size of the morphological kernel in pixels used to combine nearby motion regions and filter noise. Larger values merge more distant motion regions into single contours but may also merge separate objects. Smaller values preserve more detail but may leave fragmented detections. The kernel uses an elliptical shape. Default is 3 pixels.", |
| 104 | + examples=[3, 5, 7], |
| 105 | + default=3, |
| 106 | + ) |
107 | 107 | ) |
108 | 108 |
|
109 | | - threshold: Union[Selector(kind=[INTEGER_KIND]), int] = Field( |
| 109 | + threshold: Union[PositiveInt, Selector(kind=[INTEGER_KIND])] = Field( |
110 | 110 | title="Threshold", |
111 | 111 | description="Threshold value for the squared Mahalanobis distance used by the MOG2 background subtraction algorithm. Controls sensitivity to motion - smaller values increase sensitivity (detect smaller changes) but may produce more false positives, larger values decrease sensitivity (only detect significant changes) but may miss subtle motion. Recommended range is 8-32. Default is 16.", |
112 | | - gt=0, |
113 | 112 | examples=[16, 8, 24, 32], |
114 | 113 | default=16, |
115 | 114 | ) |
116 | 115 |
|
117 | | - history: Union[Selector(kind=[INTEGER_KIND]), int] = Field( |
| 116 | + history: Union[PositiveInt, Selector(kind=[INTEGER_KIND])] = Field( |
118 | 117 | title="History", |
119 | 118 | description="Number of previous frames used to build the background model. Controls how quickly the background adapts to changes - larger values (e.g., 50-100) create a more stable background model that's less sensitive to temporary changes but adapts slowly to permanent background changes. Smaller values (e.g., 10-20) allow faster adaptation but may treat moving objects as background if they stop moving. Default is 30 frames.", |
120 | | - gt=0, |
121 | 119 | examples=[30, 50, 100], |
122 | 120 | default=30, |
123 | 121 | ) |
|
0 commit comments