node-moving-things-tracker
Advanced tools
Comparing version 0.4.0 to 0.4.1
91
main.js
#! /usr/bin/env node | ||
var fs = require("fs"); | ||
var Tracker = require('./tracker'); | ||
var parseArgs = require('minimist') | ||
// Utilities for cleaning up detections input | ||
@@ -15,7 +16,7 @@ var isInsideSomeAreas = require('./utils').isInsideSomeAreas; | ||
// Parse CLI args | ||
var args = process.argv.slice(2); | ||
var args = parseArgs(process.argv.slice(2)); | ||
// Path to raw detections input | ||
var pathRawDetectionsInput = args[0]; | ||
var pathRawDetectionsInput = args.input; | ||
if(args.indexOf('--debug') > -1) { | ||
if(args.debug) { | ||
console.log('debug mode'); | ||
@@ -39,6 +40,7 @@ // Running in debug mode output full json | ||
// Optional params to clean up input detections | ||
var CLEAN_UP_DETECTIONS = true; | ||
var LARGEST_DETECTION_ALLOWED = 1920 * 40 / 100; | ||
var DETECT_LIST = ["car", "bicycle", "truck", "motorbike"]; | ||
// Specific mode for beat the traffic game | ||
var MODE_BEATTHETRAFFIC = args.mode === "beatthetraffic"; | ||
var LARGEST_DETECTION_ALLOWED = 1920 * 25 / 100; | ||
var DETECT_LIST = ["bicycle", "car", "motorbike", "bus", "truck", "person"]; | ||
var TRACKED_LIST = ["car", "motorbike", "truck"] | ||
var IGNORED_AREAS = []; // example: [{"x":634,"y":1022,"w":192,"h":60},{"x":1240,"y":355,"w":68,"h":68} | ||
@@ -69,3 +71,3 @@ | ||
if(CLEAN_UP_DETECTIONS) { | ||
if(MODE_BEATTHETRAFFIC) { | ||
// Remove unwanted areas | ||
@@ -76,3 +78,3 @@ detectionsForThisFrame = detectionsForThisFrame.filter((detection) => !isInsideSomeAreas(IGNORED_AREAS, detection)); | ||
// Remove objects too big | ||
detectionsForThisFrame = detections[frameNb].filter((detection) => !isDetectionTooLarge(detection, LARGEST_DETECTION_ALLOWED)); | ||
detectionsForThisFrame = detectionsForThisFrame.filter((detection) => !isDetectionTooLarge(detection, LARGEST_DETECTION_ALLOWED)); | ||
} | ||
@@ -88,31 +90,50 @@ | ||
// 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 | ||
if(MODE_BEATTHETRAFFIC) { | ||
// Overwrite name for each id with mostly matched name to avoid having | ||
// tracked item that change types | ||
// For each frame | ||
Object.keys(tracker).map((frameNb) => { | ||
tracker[frameNb] = tracker[frameNb].map((trackedItem) => { | ||
// Find | ||
var item = allTrackedItems.get(trackedItem.id) | ||
var mostlyMatchedName = trackedItem.name; | ||
if(item) { | ||
mostlyMatchedName = item.getMostlyMatchedName() | ||
} | ||
} | ||
if(debugOutput) { | ||
// console.log(trackedItem); | ||
return { | ||
...trackedItem, | ||
name : mostlyMatchedName | ||
} | ||
} 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: mostlyMatchedName, | ||
bearing: trackedItem.bearing | ||
} | ||
} | ||
}) | ||
}) | ||
}); | ||
// Remove the tracked item with the name that we won't render as clickable | ||
Object.keys(tracker).map((frameNb) => { | ||
tracker[frameNb] = tracker[frameNb].filter((trackedItem) => { | ||
if(TRACKED_LIST.indexOf(trackedItem.name) > -1) { | ||
return true | ||
} else { | ||
return false | ||
} | ||
}); | ||
}); | ||
} | ||
fs.writeFile(`${pathToTrackerOutput}`, JSON.stringify(tracker), function() { | ||
@@ -119,0 +140,0 @@ console.log('Output tracker data wrote'); |
{ | ||
"name": "node-moving-things-tracker", | ||
"version": "0.4.0", | ||
"version": "0.4.1", | ||
"description": "Tracker by detections wrote in javascript for node.js / browsers", | ||
@@ -16,4 +16,6 @@ "main": "main.js", | ||
"lodash.isequal": "^4.5.0", | ||
"uuid": "^3.1.0" | ||
} | ||
"minimist": "^1.2.0", | ||
"uuid": "^3.2.1" | ||
}, | ||
"devDependencies": {} | ||
} |
@@ -40,3 +40,3 @@ # node-moving-things-tracker | ||
```bash | ||
node-moving-things-tracker PATH_TO_YOLO_DETECTIONS.txt | ||
node-moving-things-tracker --input PATH_TO_YOLO_DETECTIONS.txt | ||
# This will output a tracker.json file in the same folder containing the tracker data | ||
@@ -106,3 +106,3 @@ ``` | ||
#Run with ---debug flag at the end | ||
node-moving-things-tracker PATH_TO_YOLO_DETECTIONS.txt --debug | ||
node-moving-things-tracker --debug --input PATH_TO_YOLO_DETECTIONS.txt | ||
``` | ||
@@ -109,0 +109,0 @@ |
Sorry, the diff of this file is not supported yet
66303
1826
3
+ Addedminimist@^1.2.0
+ Addedminimist@1.2.8(transitive)
Updateduuid@^3.2.1