norfair
norfair copied to clipboard
Simplify frame skipping logic
In norfair, whenever you skip frames, the hit_counter of each TrackedObjects gets decreased by one. Therefore, when you skip more frames than the value of the hit_counter, then the object gets destroyed, even though you didn’t even use the detector! That is undesirable. Also, the period variable doesn't seem intuitive on what is doing.
The way it works in this PR is:
- The Tracker.update method doesn't have the
periodargument, but instead it has ahit_counter_jumpvariable (which defaults to None) telling you by how much will the hit_counter get increased or decreased if the frame is not skipped. - When you call the Tracker.update method, if you pass the argument detections=None, then norfair assumes you skipped that frame, and sets
hit_counter_jump=0. If detections is a list, then Norfair assumes you didn’t skip that frame, and (by default, ifhit_counter_jump is None) setshit_counter_jumpto one plus the amount of frames that were previously skipped (so if no frames were skipped, thenhit_counter_jump=1) - Doing this, whenever you skip a frame, the hit_counters are not touched. Objects that were alive will still be alive at least until the next time you use the detector.
- Whenever you don’t skip a frame, then hit_counters get increased or decreased by hit_counter_jump (depending if they matched or not with a detection).
- When a
TrackedObjectinstance is created, it's initialhit_counteris set to 1.