add nms_threshold to config

This commit is contained in:
David Bell 2021-05-29 20:42:47 +10:00
parent abbc608ee4
commit 0831b064c1
5 changed files with 20 additions and 2 deletions

View File

@ -43,6 +43,10 @@ Global object detection settings. These may also be defined at the camera level.
detect: detect:
# Optional: Number of frames without a detection before frigate considers an object to be gone. (default: 5x the frame rate) # Optional: Number of frames without a detection before frigate considers an object to be gone. (default: 5x the frame rate)
max_disappeared: 25 max_disappeared: 25
# Optional: Non Maximum Suppression Threshold, maximum overlap between detections of each detected object type. (default: 0.4)
# Higher values mean only detections with a high amount of overlap will have lower confidence detections discarded.
# Low values mean more overlapping detections will be discarded as a smaller overlap is tolerated.
nms_threshold: 0.4
``` ```
### `logger` ### `logger`

View File

@ -287,6 +287,8 @@ cameras:
enabled: True enabled: True
# Optional: Number of frames without a detection before frigate considers an object to be gone. (default: 5x the frame rate) # Optional: Number of frames without a detection before frigate considers an object to be gone. (default: 5x the frame rate)
max_disappeared: 25 max_disappeared: 25
# Optional: Non Maximum Suppression Threshold, maximum overlap between detections of each detected object type. (default: 0.4)
nms_threshold: 0.4
# Optional: save clips configuration # Optional: save clips configuration
clips: clips:

View File

@ -187,7 +187,12 @@ class MotionConfig:
} }
GLOBAL_DETECT_SCHEMA = vol.Schema({"max_disappeared": int}) GLOBAL_DETECT_SCHEMA = vol.Schema(
{
"max_disappeared": int,
vol.Required("nms_threshold", default=0.4): vol.All(float, vol.Range(min=0, max=1)),
}
)
DETECT_SCHEMA = GLOBAL_DETECT_SCHEMA.extend( DETECT_SCHEMA = GLOBAL_DETECT_SCHEMA.extend(
{vol.Optional("enabled", default=True): bool} {vol.Optional("enabled", default=True): bool}
) )
@ -197,6 +202,7 @@ DETECT_SCHEMA = GLOBAL_DETECT_SCHEMA.extend(
class DetectConfig: class DetectConfig:
enabled: bool enabled: bool
max_disappeared: int max_disappeared: int
nms_threshold: float
@classmethod @classmethod
def build(cls, config, global_config, camera_fps) -> DetectConfig: def build(cls, config, global_config, camera_fps) -> DetectConfig:
@ -211,6 +217,7 @@ class DetectConfig:
return { return {
"enabled": self.enabled, "enabled": self.enabled,
"max_disappeared": self.max_disappeared, "max_disappeared": self.max_disappeared,
"nms_threshold": self.nms_threshold,
} }

View File

@ -111,6 +111,7 @@ class ProcessClip:
"detection_frame": mp.Value("d", 0.0), "detection_frame": mp.Value("d", 0.0),
} }
stop_event = mp.Event() stop_event = mp.Event()
nms_threshold = self.camera_config.detect.nms_threshold
model_shape = (self.config.model.height, self.config.model.width) model_shape = (self.config.model.height, self.config.model.width)
process_frames( process_frames(
@ -128,6 +129,7 @@ class ProcessClip:
object_filters, object_filters,
mask, mask,
stop_event, stop_event,
nms_threshold,
exit_on_empty=True, exit_on_empty=True,
) )

View File

@ -348,6 +348,7 @@ def track_camera(
) )
object_tracker = ObjectTracker(config.detect) object_tracker = ObjectTracker(config.detect)
nms_threshold = config.detect.nms_threshold
frame_manager = SharedMemoryFrameManager() frame_manager = SharedMemoryFrameManager()
@ -365,6 +366,7 @@ def track_camera(
objects_to_track, objects_to_track,
object_filters, object_filters,
detection_enabled, detection_enabled,
nms_threshold,
stop_event, stop_event,
) )
@ -436,6 +438,7 @@ def process_frames(
object_filters, object_filters,
detection_enabled: mp.Value, detection_enabled: mp.Value,
stop_event, stop_event,
nms_threshold,
exit_on_empty: bool = False, exit_on_empty: bool = False,
): ):
@ -540,7 +543,7 @@ def process_frames(
for o in group for o in group
] ]
confidences = [o[1] for o in group] confidences = [o[1] for o in group]
idxs = cv2.dnn.NMSBoxes(boxes, confidences, 0.5, 0.4) idxs = cv2.dnn.NMSBoxes(boxes, confidences, 0.5, nms_threshold)
for index in idxs: for index in idxs:
obj = group[index[0]] obj = group[index[0]]