Detector-agnostic online multi-object tracking in MoonBit
Dependencies
moon fmt --check
moon check --target all --deny-warn
moon test --target all --deny-warnlet tracker = @mbmot.Tracker::new(@mbmot.TrackerConfig::default())
let box = @mbmot.BoundingBox::new(12.0, 20.0, 52.0, 80.0)
let detection = @mbmot.Detection::new(box, 0.91, 0)
let frame = tracker.update(1, [detection])
let track = frame.tracks()[0]
assert_eq(track.track_id(), 1)
assert_eq(track.hits(), 1)| 参数 | 值 | 作用 |
|---|---|---|
| high_score_threshold | 0.25 | 第一阶段检测下限 |
| low_score_threshold | 0.10 | 第二阶段检测下限 |
| new_track_threshold | 0.25 | 新建身份的最低分数 |
| first_match_max_cost | 0.80 | 高分关联最大代价 |
| second_match_max_cost | 0.50 | 低分关联最大代价 |
| max_lost_frames | 30 | lost 身份的保留帧数 |
| min_hits | 1 | 轨迹可见前所需命中数 |
| fuse_score | true | 第一阶段是否融合检测分数 |
{"frame":1,"detections":[{"xyxy":[0,0,10,10],"score":0.95,"class_id":0}]}moon run src/replay --target native < examples/replay.ndjsoncmd /c "moon run src/replay --target native < examples\replay.ndjson"{"frame":1,"tracks":[{"track_id":1,"xyxy":[0,0,10,10],"score":0.95,"class_id":0,"first_frame":1,"last_frame":1,"hits":1}],"lost":[],"removed":[]}pub(all) suberror TrackerError {
InvalidBoundingBox(String)
InvalidScore(Double)
InvalidClassId(Int)
InvalidConfig(String)
NonIncreasingFrame(previous~ : Int, received~ : Int)
InvalidDetection(index~ : Int)
} derive(Debug)fn BoundingBox::from_cxcywh(center_x : Double, center_y : Double, width : Double, height : Double) -> BoundingBox raise TrackerErrorfn BoundingBox::from_xywh(x : Double, y : Double, width : Double, height : Double) -> BoundingBox raise TrackerErrorfn BoundingBox::new(x1 : Double, y1 : Double, x2 : Double, y2 : Double) -> BoundingBox raise TrackerErrorfn Detection::new(bbox : BoundingBox, score : Double, class_id : Int) -> Detection raise TrackerErrorpub struct Track {
track_id : Int
bbox : BoundingBox
class_id : Int
score : Double
first_frame : Int
last_frame : Int
hits : Int
} derive(Eq, Debug)type Trackerfn Tracker::update(self : Tracker, frame_id : Int, detections : Array[Detection]) -> FrameTracks raise TrackerErrorfn TrackerConfig::new(high_score_threshold~ : Double, low_score_threshold~ : Double, new_track_threshold~ : Double, first_match_max_cost~ : Double, second_match_max_cost~ : Double, max_lost_frames~ : Int, min_hits~ : Int, fuse_score~ : Bool) -> TrackerConfig raise TrackerErrortype TrackerStatusInstall
Download zipDetector-agnostic online multi-object tracking in MoonBit
Dependencies