Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 5 additions & 13 deletions ItemTracked.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,17 @@ var computeVelocityVector = require('./utils').computeVelocityVector
// Use a simple incremental unique id for the display
var idDisplay = 0;

// Default Params
const params = {
// Remove new objects fast if they could not be matched in the next frames.
// Setting this to false ensures the object will stick around at least
// DEFAULT_UNMATCHEDFRAMES_TOLERANCE frames, even if they could neven be
// matched in subsequent frames.
fastDelete: true
}

exports.ItemTracked = function(properties, frameNb, DEFAULT_UNMATCHEDFRAMES_TOLERANCE){
var DEFAULT_UNMATCHEDFRAMES_TOLERANCE = DEFAULT_UNMATCHEDFRAMES_TOLERANCE;
exports.ItemTracked = function(properties, frameNb, unMatchedFramesTolerance, fastDelete){
var DEFAULT_UNMATCHEDFRAMES_TOLERANCE = unMatchedFramesTolerance;
var itemTracked = {};
// ==== Private =====
// Am I available to be matched?
itemTracked.available = true;
// Should I be deleted?
itemTracked.delete = false;
itemTracked.fastDelete = fastDelete;
// How many unmatched frame should I survive?
itemTracked.frameUnmatchedLeftBeforeDying = DEFAULT_UNMATCHEDFRAMES_TOLERANCE;
itemTracked.frameUnmatchedLeftBeforeDying = unMatchedFramesTolerance;
itemTracked.isZombie = false;
itemTracked.appearFrame = frameNb;
itemTracked.disappearFrame = null;
Expand Down Expand Up @@ -120,7 +112,7 @@ exports.ItemTracked = function(properties, frameNb, DEFAULT_UNMATCHEDFRAMES_TOLE
this.frameUnmatchedLeftBeforeDying--;
this.isZombie = true;
// If it was matched less than 1 time, it should die quick
if(params.fastDelete && this.nbTimeMatched <= 1) {
if(this.fastDelete && this.nbTimeMatched <= 1) {
this.frameUnmatchedLeftBeforeDying = -1;
}
}
Expand Down
6 changes: 2 additions & 4 deletions spec/Tracker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ describe('Tracker', function () {
beforeEach(function () {
Tracker.reset();
Tracker.setParams({
items: {
fastDelete: true
},
fastDelete: true,
unMatchedFramesTolerance: 5,
iouLimit: 0.05
});
Expand All @@ -76,7 +74,7 @@ describe('Tracker', function () {
});

it('keeps the item if fastDelete is disabled', function () {
Tracker.setParams({ items: { fastDelete: false } });
Tracker.setParams({ fastDelete: false });
Tracker.reset();

detections.forEach((frame, frameNb) => {
Expand Down
41 changes: 20 additions & 21 deletions tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,19 @@ var iouAreas = require('./utils').iouAreas

var DEBUG_MODE = false;

// DEFAULT_UNMATCHEDFRAMES_TOLERANCE
// This the number of frame we wait when an object isn't matched before considering it gone
var DEFAULT_UNMATCHEDFRAMES_TOLERANCE = 5;
// IOU_LIMIT, exclude things from beeing matched if their IOU is lower than this
// 1 means total overlap whereas 0 means no overlap
var IOU_LIMIT = 0.05
const params = {
// DEFAULT_UNMATCHEDFRAMES_TOLERANCE
// This the number of frame we wait when an object isn't matched before considering it gone
unMatchedFramesTolerance: 5,
// DEFAULT_IOU_LIMIT, exclude things from beeing matched if their IOU is lower than this
// 1 means total overlap whereas 0 means no overlap
iouLimit: 0.05,
// Remove new objects fast if they could not be matched in the next frames.
// Setting this to false ensures the object will stick around at least
// unMatchedFramesTolerance frames, even if they could neven be matched in
// subsequent frames.
fastDelete: true
}

// A dictionary of itemTracked currently tracked
// key: uuid
Expand Down Expand Up @@ -40,7 +47,7 @@ const computeDistance = function(item1, item2) {
var distance = 1 - iou;

// If the overlap is iou < 0.95, exclude value
if(distance > (1 - IOU_LIMIT)) {
if(distance > (1 - params.iouLimit)) {
distance = KDTREESEARCH_LIMIT + 1;
}

Expand All @@ -62,7 +69,7 @@ exports.updateTrackedItemsWithNewFrame = function(detectionsOfThisFrame, frameNb
if(mapOfItemsTracked.size === 0) {
// Just add every detected item as item Tracked
detectionsOfThisFrame.forEach(function(itemDetected) {
var newItemTracked = new ItemTracked(itemDetected, frameNb, DEFAULT_UNMATCHEDFRAMES_TOLERANCE)
var newItemTracked = new ItemTracked(itemDetected, frameNb, params.unMatchedFramesTolerance, params.fastDelete)
// Add it to the map
mapOfItemsTracked.set(newItemTracked.id, newItemTracked)
// Add it to the kd tree
Expand Down Expand Up @@ -189,7 +196,7 @@ exports.updateTrackedItemsWithNewFrame = function(detectionsOfThisFrame, frameNb
var treeSearchResult = treeItemsTracked.nearest(detectionsOfThisFrame[index], 1, KDTREESEARCH_LIMIT)[0];

if(!treeSearchResult) {
var newItemTracked = ItemTracked(detectionsOfThisFrame[index], frameNb, DEFAULT_UNMATCHEDFRAMES_TOLERANCE)
var newItemTracked = ItemTracked(detectionsOfThisFrame[index], frameNb, params.unMatchedFramesTolerance, params.fastDelete)
// Add it to the map
mapOfItemsTracked.set(newItemTracked.id, newItemTracked)
// Add it to the kd tree
Expand Down Expand Up @@ -228,18 +235,10 @@ exports.reset = function() {
itemTrackedModule.reset();
}

exports.setParams = function(params) {
if(params.unMatchedFramesTolerance) {
DEFAULT_UNMATCHEDFRAMES_TOLERANCE = params.unMatchedFramesTolerance;
}
if(params.iouLimit) {
IOU_LIMIT = params.iouLimit;
}

// To keep the API simple, we just move the params down to the ItemsTracked as well.
if("items" in params) {
itemTrackedModule.setParams(params.items);
}
exports.setParams = function(newParams) {
Object.keys(newParams).forEach((key) => {
params[key] = newParams[key];
});
}

exports.enableKeepInMemory = function() {
Expand Down