mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-04-29 18:17:40 +03:00
Cleanup mypy
This commit is contained in:
parent
ef6fc22ec6
commit
ccd1e8040d
@ -5,15 +5,10 @@ from typing import Any, Sequence
|
|||||||
|
|
||||||
import cv2
|
import cv2
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from norfair import (
|
from norfair.drawing.draw_boxes import draw_boxes
|
||||||
Detection,
|
from norfair.drawing.drawer import Drawable, Drawer
|
||||||
Drawable,
|
from norfair.filter import OptimizedKalmanFilterFactory
|
||||||
OptimizedKalmanFilterFactory,
|
from norfair.tracker import Detection, TrackedObject, Tracker
|
||||||
Tracker,
|
|
||||||
draw_boxes,
|
|
||||||
)
|
|
||||||
from norfair.drawing.drawer import Drawer
|
|
||||||
from norfair.tracker import TrackedObject
|
|
||||||
from rich import print
|
from rich import print
|
||||||
from rich.console import Console
|
from rich.console import Console
|
||||||
from rich.table import Table
|
from rich.table import Table
|
||||||
@ -198,19 +193,21 @@ class NorfairTracker(ObjectTracker):
|
|||||||
self.default_tracker = {
|
self.default_tracker = {
|
||||||
"static": Tracker(
|
"static": Tracker(
|
||||||
distance_function=frigate_distance,
|
distance_function=frigate_distance,
|
||||||
distance_threshold=self.default_tracker_config["distance_threshold"],
|
distance_threshold=self.default_tracker_config[ # type: ignore[arg-type]
|
||||||
|
"distance_threshold"
|
||||||
|
],
|
||||||
initialization_delay=self.detect_config.min_initialized,
|
initialization_delay=self.detect_config.min_initialized,
|
||||||
hit_counter_max=self.detect_config.max_disappeared,
|
hit_counter_max=self.detect_config.max_disappeared, # type: ignore[arg-type]
|
||||||
filter_factory=self.default_tracker_config["filter_factory"],
|
filter_factory=self.default_tracker_config["filter_factory"], # type: ignore[arg-type]
|
||||||
),
|
),
|
||||||
"ptz": Tracker(
|
"ptz": Tracker(
|
||||||
distance_function=frigate_distance,
|
distance_function=frigate_distance,
|
||||||
distance_threshold=self.default_ptz_tracker_config[
|
distance_threshold=self.default_ptz_tracker_config[
|
||||||
"distance_threshold"
|
"distance_threshold"
|
||||||
],
|
], # type: ignore[arg-type]
|
||||||
initialization_delay=self.detect_config.min_initialized,
|
initialization_delay=self.detect_config.min_initialized,
|
||||||
hit_counter_max=self.detect_config.max_disappeared,
|
hit_counter_max=self.detect_config.max_disappeared, # type: ignore[arg-type]
|
||||||
filter_factory=self.default_ptz_tracker_config["filter_factory"],
|
filter_factory=self.default_ptz_tracker_config["filter_factory"], # type: ignore[arg-type]
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -273,7 +270,7 @@ class NorfairTracker(ObjectTracker):
|
|||||||
# Get the correct tracker for this object's label
|
# Get the correct tracker for this object's label
|
||||||
tracker = self.get_tracker(obj["label"])
|
tracker = self.get_tracker(obj["label"])
|
||||||
obj_match = next(
|
obj_match = next(
|
||||||
(o for o in tracker.tracked_objects if o.global_id == track_id), None
|
(o for o in tracker.tracked_objects if str(o.global_id) == track_id), None
|
||||||
)
|
)
|
||||||
# if we don't have a match, we have a new object
|
# if we don't have a match, we have a new object
|
||||||
obj["score_history"] = (
|
obj["score_history"] = (
|
||||||
@ -317,7 +314,7 @@ class NorfairTracker(ObjectTracker):
|
|||||||
tracker.tracked_objects = [
|
tracker.tracked_objects = [
|
||||||
o
|
o
|
||||||
for o in tracker.tracked_objects
|
for o in tracker.tracked_objects
|
||||||
if o.global_id != track_id and o.hit_counter < 0
|
if str(o.global_id) != track_id and o.hit_counter < 0
|
||||||
]
|
]
|
||||||
|
|
||||||
del self.track_id_map[track_id]
|
del self.track_id_map[track_id]
|
||||||
@ -565,12 +562,12 @@ class NorfairTracker(ObjectTracker):
|
|||||||
"estimate": estimate,
|
"estimate": estimate,
|
||||||
"estimate_velocity": t.estimate_velocity,
|
"estimate_velocity": t.estimate_velocity,
|
||||||
}
|
}
|
||||||
active_ids.append(t.global_id)
|
active_ids.append(str(t.global_id))
|
||||||
if t.global_id not in self.track_id_map:
|
if str(t.global_id) not in self.track_id_map:
|
||||||
self.register(t.global_id, new_obj)
|
self.register(str(t.global_id), new_obj)
|
||||||
# if there wasn't a detection in this frame, increment disappeared
|
# if there wasn't a detection in this frame, increment disappeared
|
||||||
elif t.last_detection.data["frame_time"] != frame_time:
|
elif t.last_detection.data["frame_time"] != frame_time:
|
||||||
id = self.track_id_map[t.global_id]
|
id = self.track_id_map[str(t.global_id)]
|
||||||
self.disappeared[id] += 1
|
self.disappeared[id] += 1
|
||||||
# sometimes the estimate gets way off
|
# sometimes the estimate gets way off
|
||||||
# only update if the upper left corner is actually upper left
|
# only update if the upper left corner is actually upper left
|
||||||
@ -578,7 +575,7 @@ class NorfairTracker(ObjectTracker):
|
|||||||
self.tracked_objects[id]["estimate"] = new_obj["estimate"]
|
self.tracked_objects[id]["estimate"] = new_obj["estimate"]
|
||||||
# else update it
|
# else update it
|
||||||
else:
|
else:
|
||||||
self.update(t.global_id, new_obj)
|
self.update(str(t.global_id), new_obj)
|
||||||
|
|
||||||
# clear expired tracks
|
# clear expired tracks
|
||||||
expired_ids = [k for k in self.track_id_map.keys() if k not in active_ids]
|
expired_ids = [k for k in self.track_id_map.keys() if k not in active_ids]
|
||||||
@ -613,7 +610,7 @@ class NorfairTracker(ObjectTracker):
|
|||||||
|
|
||||||
def debug_draw(self, frame: np.ndarray, frame_time: float) -> None:
|
def debug_draw(self, frame: np.ndarray, frame_time: float) -> None:
|
||||||
# Collect all tracked objects from each tracker
|
# Collect all tracked objects from each tracker
|
||||||
all_tracked_objects = []
|
all_tracked_objects: list[TrackedObject] = []
|
||||||
|
|
||||||
# print a table to the console with norfair tracked object info
|
# print a table to the console with norfair tracked object info
|
||||||
if False:
|
if False:
|
||||||
@ -644,9 +641,9 @@ class NorfairTracker(ObjectTracker):
|
|||||||
# draw the estimated bounding box
|
# draw the estimated bounding box
|
||||||
draw_boxes(frame, all_tracked_objects, color="green", draw_ids=True)
|
draw_boxes(frame, all_tracked_objects, color="green", draw_ids=True)
|
||||||
# draw the detections that were detected in the current frame
|
# draw the detections that were detected in the current frame
|
||||||
draw_boxes(frame, active_detections, color="blue", draw_ids=True)
|
draw_boxes(frame, active_detections, color="blue", draw_ids=True) # type: ignore[arg-type]
|
||||||
# draw the detections that are missing in the current frame
|
# draw the detections that are missing in the current frame
|
||||||
draw_boxes(frame, missing_detections, color="red", draw_ids=True)
|
draw_boxes(frame, missing_detections, color="red", draw_ids=True) # type: ignore[arg-type]
|
||||||
|
|
||||||
# draw the distance calculation for the last detection
|
# draw the distance calculation for the last detection
|
||||||
# estimate vs detection
|
# estimate vs detection
|
||||||
@ -654,8 +651,8 @@ class NorfairTracker(ObjectTracker):
|
|||||||
ld = obj.last_detection
|
ld = obj.last_detection
|
||||||
# bottom right
|
# bottom right
|
||||||
text_anchor = (
|
text_anchor = (
|
||||||
ld.points[1, 0],
|
ld.points[1, 0], # type: ignore[index]
|
||||||
ld.points[1, 1],
|
ld.points[1, 1], # type: ignore[index]
|
||||||
)
|
)
|
||||||
frame = Drawer.text(
|
frame = Drawer.text(
|
||||||
frame,
|
frame,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user