opendatacam / node-moving-things-tracker

javascript implementation of "tracker by detections" for realtime multiple object tracking (MOT)
MIT License
106 stars 26 forks source link

Features: Reset idDisplay, configurable fast delete and custom distance function #19

Closed vsaw closed 4 years ago

vsaw commented 4 years ago

This pull request contains 3 improvements

1. Reset idDisplay

Resetting the tracker did not affect the item ID. Therefore multiple tests runs on the same file were difficult to evaluate as one had to offset the later runs to get the actual number of the items tracked.

This pull request fixes this. As it introduces a new reset function for ItemsTracked.

To prove it is working, jasmine tests with GitHub Actions are included. As GitHub does not run the checks in the opendatacam repository see the passing checks in my fork here: https://github.com/vsaw/node-moving-things-tracker/actions/runs/202256302

2. Configurable Fast Delete

This allows to configure if detections should be removed quickly in cases where they were detected and could not be matched afterwards.

Fast deletion can be enabled/disabled via:

Tracker.setParams({ fastDelete: false });

Again passing tests can be see here https://github.com/vsaw/node-moving-things-tracker/pull/2/checks

3. Custom Distance Function

In cases where one wants to try with a custom distance function it can now be passed to the Tracer as follows:

// See https://en.wikipedia.org/wiki/Taxicab_geometry
function l1metric(item1, item2) {
  // Get the x and y distance, in relation to the item size
  const xDist = Math.abs(item1.x - item2.x) / ((item1.w + item2.w) / 2);
  const yDist = Math.abs(item1.y - item2.y) / ((item1.h + item2.h) / 2);
  return xDist + yDist;
}

Tracker.setParams({ distanceFunc: l1metric });

As usual passing tests can be found here: https://github.com/vsaw/node-moving-things-tracker/actions/runs/203819989

tdurand commented 4 years ago

Hi,

Thanks for cleaning up and improving this messy code ;-) ..

Seems good to me, could release this as a new version of the node package and add it to OpenDataCam

curious if for your use case if you found some good improvements from tweaking the tracker ?

vsaw commented 4 years ago

Hi @tdurand

Thanks for cleaning up and improving this messy code ;-) ..

Thank you for putting up the hard work and writing it in the first place 🙂

Seems good to me, could release this as a new version of the node package and add it to OpenDataCam

I've bumped the version, but I'm unsure if I can push a new version to npmjs. Once we a new version up on npm I'd be happy to update the dependency in OpenDataCam itself.

curious if for your use case if you found some good improvements from tweaking the tracker ?

I guess my results are highly use case specific, but when tracking small objects (< 5% of relative size) the objects were often moving to fast for the tracker to have an overlap between two frames. Therefore

  1. I disabled the "fast delete" so we have a few more objects to match against.
  2. I created a custom distance function which tolerated small gaps between objects. I effectively "inflated" the objects a bit, to make their area bigger than what YOLO detected, before running them through the regular iouDistance function.

In my case this had a significant impact on the number of IDs the tracker produced.

chart

OpenDataCam itself did not have this dramatic increase of counted objects, but I was still able to track 12% more objects on average.

tdurand commented 4 years ago

@vsaw nice, no I think I need to push it myself for the rights for npm... will do now.

Many thanks for the inputs.. makes sense if there are too small object.. and yes main problem is that everything tends to be use case specific so no real winner ;-)

Glad OpenDataCam was a good starting base for your project

tdurand commented 4 years ago

I just published v8.0.0 on npm and added a release: https://github.com/opendatacam/node-moving-things-tracker/releases

Hopefully this will helps you avoid maintaining a fork on your end ..

vsaw commented 4 years ago

@vsaw nice, no I think I need to push it myself for the rights for npm... will do now.

Maybe a GitHub Action such as https://github.com/marketplace/actions/npm-publish could help to take the grunt work out of it :-)

Glad OpenDataCam was a good starting base for your project

Yes, thanks again for opening it up for others!