node-moving-things-tracker
Advanced tools
Comparing version
@@ -32,2 +32,5 @@ var uuidv4 = require('uuid/v4'); | ||
itemTracked.disappearArea = {}; | ||
// Keep track of the most counted class | ||
itemTracked.nameCount = {}; | ||
itemTracked.nameCount[properties.name] = 1; | ||
// ==== Public ===== | ||
@@ -76,2 +79,7 @@ itemTracked.x = properties.x; | ||
this.name = properties.name; | ||
if(this.nameCount[properties.name]) { | ||
this.nameCount[properties.name]++; | ||
} else { | ||
this.nameCount[properties.name] = 1; | ||
} | ||
// Reset dying counter | ||
@@ -141,13 +149,25 @@ this.frameUnmatchedLeftBeforeDying = DEFAULT_UNMATCHEDFRAMES_TOLERANCE | ||
itemTracked.toJSON = function() { | ||
itemTracked.getMostlyMatchedName = function() { | ||
var nameMostlyMatchedOccurences = 0; | ||
var nameMostlyMatched = ''; | ||
Object.keys(this.nameCount).map((name) => { | ||
if(this.nameCount[name] > nameMostlyMatchedOccurences) { | ||
nameMostlyMatched = name; | ||
nameMostlyMatchedOccurences = this.nameCount[name] | ||
} | ||
}) | ||
return nameMostlyMatched; | ||
} | ||
itemTracked.toJSONDebug = function() { | ||
return { | ||
id: this.id, | ||
idDisplay: this.idDisplay, | ||
x: this.x, | ||
y: this.y, | ||
w: this.w, | ||
h: this.h, | ||
x: parseInt(this.x, 10), | ||
y: parseInt(this.y, 10), | ||
w: parseInt(this.w, 10), | ||
h: parseInt(this.h, 10), | ||
// Here we negate dy to be in "normal" carthesian coordinates | ||
bearing: computeBearingIn360(this.velocity.dx, - this.velocity.dy), | ||
name: this.name, | ||
bearing: parseInt(computeBearingIn360(this.velocity.dx, - this.velocity.dy)), | ||
name: this.getMostlyMatchedName(), | ||
isZombie: this.isZombie, | ||
@@ -158,2 +178,16 @@ appearFrame: this.appearFrame, | ||
} | ||
itemTracked.toJSON = function() { | ||
return { | ||
id: this.idDisplay, | ||
x: parseInt(this.x, 10), | ||
y: parseInt(this.y, 10), | ||
w: parseInt(this.w, 10), | ||
h: parseInt(this.h, 10), | ||
// Here we negate dy to be in "normal" carthesian coordinates | ||
bearing: parseInt(computeBearingIn360(this.velocity.dx, - this.velocity.dy), 10), | ||
name: this.getMostlyMatchedName() | ||
} | ||
} | ||
itemTracked.toJSONGenericInfo = function() { | ||
@@ -166,3 +200,4 @@ return { | ||
disappearArea: this.disappearArea, | ||
nbActiveFrame: this.disappearFrame - this.appearFrame | ||
nbActiveFrame: this.disappearFrame - this.appearFrame, | ||
name: this.getMostlyMatchedName() | ||
} | ||
@@ -169,0 +204,0 @@ } |
42
main.js
@@ -12,2 +12,4 @@ #! /usr/bin/env node | ||
var debugOutput = false; | ||
// Parse CLI args | ||
@@ -18,2 +20,8 @@ var args = process.argv.slice(2); | ||
if(args.indexOf('--debug') > -1) { | ||
console.log('debug mode'); | ||
// Running in debug mode output full json | ||
debugOutput = true; | ||
} | ||
// If input path not specified abort | ||
@@ -72,5 +80,37 @@ if(!pathRawDetectionsInput) { | ||
tracker[frameNb] = Tracker.getJSONOfTrackedItems(); | ||
tracker[frameNb] = Tracker.getJSONDebugOfTrackedItems(); | ||
}); | ||
var allTrackedItems = Tracker.getAllTrackedItems(); | ||
// Overwrite name for each id with mostly matched name to avoid having | ||
// tracked item that change types | ||
// For each frame | ||
tracker = Object.keys(tracker).map((frameNb) => { | ||
return tracker[frameNb].map((trackedItem) => { | ||
// Find | ||
var item = allTrackedItems.get(trackedItem.id) | ||
// Overwrite name | ||
if(item) { | ||
trackedItem.name = item.name | ||
} | ||
if(debugOutput) { | ||
return trackedItem; | ||
} else { | ||
// If not debug, excude some fields | ||
// Ugly, would need an getJSON() as a utility function to avoid quote duplication | ||
return { | ||
id: trackedItem.idDisplay, | ||
x: trackedItem.x, | ||
y: trackedItem.y, | ||
w: trackedItem.w, | ||
h: trackedItem.h, | ||
name: trackedItem.name, | ||
bearing: trackedItem.bearing | ||
} | ||
} | ||
}) | ||
}); | ||
fs.writeFile(`${pathToTrackerOutput}`, JSON.stringify(tracker), function() { | ||
@@ -77,0 +117,0 @@ console.log('Output tracker data wrote'); |
{ | ||
"name": "node-moving-things-tracker", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "Tracker by detections wrote in javascript for node.js / browsers", | ||
@@ -5,0 +5,0 @@ "main": "main.js", |
@@ -75,2 +75,4 @@ # node-moving-things-tracker | ||
_Normal mode:_ | ||
```javascript | ||
@@ -80,3 +82,34 @@ { | ||
"43": [ | ||
{ | ||
"id": 0, | ||
"x": 628, | ||
"y": 144, | ||
"w": 48, | ||
"h": 29, | ||
"name": "car", | ||
}, | ||
{ | ||
"id": 1, | ||
"x": 620, | ||
"y": 154, | ||
"w": 50, | ||
"h": 35, | ||
"name": "car", | ||
} | ||
] | ||
} | ||
``` | ||
_Debug mode:_ | ||
```bash | ||
#Run with ---debug flag at the end | ||
node-moving-things-tracker PATH_TO_YOLO_DETECTIONS.txt --debug | ||
``` | ||
```javascript | ||
{ | ||
// Tracker data for each frame | ||
"43": [ | ||
{ | ||
"id": "900e36a2-cbc7-427c-83a9-819d072391f0", | ||
@@ -83,0 +116,0 @@ "idDisplay": 0, |
@@ -224,2 +224,12 @@ var ItemTracked = require('./ItemTracked').ItemTracked; | ||
exports.getJSONDebugOfTrackedItems = function() { | ||
return Array.from(mapOfItemsTracked.values()).map(function(itemTracked) { | ||
return itemTracked.toJSONDebug(); | ||
}); | ||
}; | ||
exports.getAllTrackedItems = function() { | ||
return mapOfAllItemsTracked; | ||
}; | ||
exports.getJSONOfAllTrackedItems = function() { | ||
@@ -226,0 +236,0 @@ return Array.from(mapOfAllItemsTracked.values()).map(function(itemTracked) { |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
65353
4.84%1808
4.33%146
29.2%0
-100%