Skip to content

Commit

Permalink
Evo: turning keeping all history in memory optional #11
Browse files Browse the repository at this point in the history
  • Loading branch information
tdurand committed Jul 1, 2019
1 parent 40419f9 commit b82d9c6
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# node-moving-things-tracker

node-moving-things-tracker is a javascript implementation of the _"tracker by detections"_ for realtime multiple object tracking (MOT) in node.js / browsers.
node-moving-things-tracker is a javascript implementation of a _"tracker by detections"_ for realtime multiple object tracking (MOT) in node.js / browsers.

Commissioned by moovel lab for [Beat the Traffic X](http://beatthetraffic.moovellab.com/) and the [Open Data Cam](http://opendatacam.moovellab.com/) project.

## confidencelem
## Problem

How to track persistently multiple moving things from frame-by-frame object detections inputs? How to assign an unique identifier to frame-by-frame object detection results?

Expand Down
5 changes: 5 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ var detections = {}
// Store tracker output
var tracker = {}

// If MODE is BEATTHETRAFFIC keep all tracker history in memory
if(MODE_BEATTHETRAFFIC) {
Tracker.enableKeepInMemory();
}

// Parse detections input
fs.readFile(`${pathRawDetectionsInput}`, function(err, f){
var lines = f.toString().split('\n');
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-moving-things-tracker",
"version": "0.5.4",
"version": "0.6.0",
"description": "Tracker by detections in javascript for node.js / browsers",
"url": "https://github.com/tdurand/node-moving-things-tracker",
"main": "main.js",
Expand Down
17 changes: 16 additions & 1 deletion tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ var mapOfItemsTracked = new Map();
// Useful to ouput the file of all items tracked
var mapOfAllItemsTracked = new Map();

// By default, we do not keep all the history in memory
var keepAllHistoryInMemory = false;

// Implementation detail, we store the distance in a KDTREE, we want to be able to exclude values from
// the kdtree search by assigning them KDTREESEARCH_LIMIT + 1
var KDTREESEARCH_LIMIT = 10000;
Expand Down Expand Up @@ -202,7 +205,9 @@ exports.updateTrackedItemsWithNewFrame = function(detectionsOfThisFrame, frameNb
if(itemTracked.isDead()) {
mapOfItemsTracked.delete(itemTracked.id);
treeItemsTracked.remove(itemTracked);
mapOfAllItemsTracked.set(itemTracked.id, itemTracked);
if(keepAllHistoryInMemory) {
mapOfAllItemsTracked.set(itemTracked.id, itemTracked);
}
}
}
});
Expand All @@ -215,6 +220,14 @@ exports.reset = function() {
mapOfAllItemsTracked = new Map();
}

exports.enableKeepInMemory = function() {
keepAllHistoryInMemory = true;
}

exports.disableKeepInMemory = function() {
keepAllHistoryInMemory = false;
}

exports.getJSONOfTrackedItems = function() {
return Array.from(mapOfItemsTracked.values()).map(function(itemTracked) {
return itemTracked.toJSON();
Expand All @@ -227,10 +240,12 @@ exports.getJSONDebugOfTrackedItems = function() {
});
};

// Work only if keepInMemory is enabled
exports.getAllTrackedItems = function() {
return mapOfAllItemsTracked;
};

// Work only if keepInMemory is enabled
exports.getJSONOfAllTrackedItems = function() {
return Array.from(mapOfAllItemsTracked.values()).map(function(itemTracked) {
return itemTracked.toJSONGenericInfo();
Expand Down

0 comments on commit b82d9c6

Please sign in to comment.