From 4c0647f38e54005c4908c74176574af377610a7b Mon Sep 17 00:00:00 2001 From: Adrian Kretz Date: Thu, 24 Jun 2021 16:56:19 +0200 Subject: [PATCH] Use box center as reference point everywhere --- ItemTracked.js | 2 +- main.js | 11 +++++++---- utils.js | 18 +++++++++--------- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/ItemTracked.js b/ItemTracked.js index dea1160..c1e78b6 100644 --- a/ItemTracked.js +++ b/ItemTracked.js @@ -196,7 +196,7 @@ exports.ItemTracked = function(properties, frameNb, unMatchedFramesTolerance, fa } itemTracked.toMOT = function(frameIndex) { - return `${frameIndex},${this.idDisplay},${this.x},${this.y},${this.w},${this.h},${this.confidence / 100},-1,-1,-1`; + return `${frameIndex},${this.idDisplay},${this.x - this.w / 2},${this.y - this.h / 2},${this.w},${this.h},${this.confidence / 100},-1,-1,-1`; } itemTracked.toJSONGenericInfo = function() { diff --git a/main.js b/main.js index fc98f1f..2a7a938 100755 --- a/main.js +++ b/main.js @@ -135,11 +135,14 @@ fs.readFile(`${pathRawDetectionsInput}`, function (err, f) { var detectionOfThisFrameArray = line.split(","); var detectionFrameIndex = parseInt(detectionOfThisFrameArray[0], 10); if (!Number.isNaN(detectionFrameIndex)) { + var w = parseFloat(detectionOfThisFrameArray[4]); + var h = parseFloat(detectionOfThisFrameArray[5]); + var detection = { - x: parseFloat(detectionOfThisFrameArray[2]), - y: parseFloat(detectionOfThisFrameArray[3]), - w: parseFloat(detectionOfThisFrameArray[4]), - h: parseFloat(detectionOfThisFrameArray[5]), + x: parseFloat(detectionOfThisFrameArray[2]) + w / 2, + y: parseFloat(detectionOfThisFrameArray[3]) + h / 2, + w, + h, confidence: parseFloat(detectionOfThisFrameArray[6]) * 100, name: "" } diff --git a/utils.js b/utils.js index 1a5512f..30f6436 100644 --- a/utils.js +++ b/utils.js @@ -7,11 +7,11 @@ exports.isDetectionTooLarge = (detections, largestAllowed) => { } const isInsideArea = (area, point) => { - const xMin = area.x - const xMax = area.x + area.w; - const yMin = area.y - const yMax = area.y + area.h; - + const xMin = area.x - area.w / 2; + const xMax = area.x + area.w / 2; + const yMin = area.y - area.h / 2; + const yMax = area.y + area.h / 2; + if(point.x >= xMin && point.x <= xMax && point.y >= yMin && @@ -35,10 +35,10 @@ exports.ignoreObjectsNotToDetect = (detections, objectsToDetect) => { const getRectangleEdges = (item) => { return { - x0: item.x, - y0: item.y, - x1: item.x + item.w, - y1: item.y + item.h + x0: item.x - item.w / 2, + y0: item.y - item.h / 2, + x1: item.x + item.w / 2, + y1: item.y + item.h / 2, } }