From b5c0e4433697ca8438f18317312cef5ce3dbef76 Mon Sep 17 00:00:00 2001 From: Ulrich Krispel Date: Thu, 3 Dec 2015 15:09:16 +0100 Subject: [PATCH 1/6] small fixes --- src/api/controllers/RiseController.js | 10 +++++++--- src/bindings/wiregen/index.js | 3 ++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/api/controllers/RiseController.js b/src/api/controllers/RiseController.js index 784eaa5..8e4e5d9 100644 --- a/src/api/controllers/RiseController.js +++ b/src/api/controllers/RiseController.js @@ -151,6 +151,7 @@ function prepareWiregen(session) { } function startWiregen(session) { + return new Promise(function(resolve, reject) { console.log('[SessionController::start Wiregen]'); prepareWiregen(session); @@ -158,11 +159,14 @@ function startWiregen(session) { wiregen.importDetections(session) .then(createInputSymbolList) .then(wiregen.createWiregenImages) - .then(wireGenResultSvg_grammar) - .then(wireGenResultSvg_hypothesis).then(function() { + //.then(wireGenResultSvg_grammar) + //.then(wireGenResultSvg_hypothesis) + .then(function() { console.log("[startWiregen::finished]"); resolve(session); - }); + }).catch(function(err) { + console.log('blablubb:' + err); + }); }); } diff --git a/src/bindings/wiregen/index.js b/src/bindings/wiregen/index.js index e07603b..c08f6fc 100644 --- a/src/bindings/wiregen/index.js +++ b/src/bindings/wiregen/index.js @@ -198,7 +198,7 @@ Wiregen.prototype.createWiregenImages = function(session) { console.log('[Wiregen-binding] child process exited with code ' + code); session.status = 'finished-Wiregen'; - if (code === 0) { + if (code == 0) { // copy lowres ortho images var files = fs.readdirSync(path.join(session.orthoresult, 'lowres')); files.forEach(function(fname) { @@ -208,6 +208,7 @@ Wiregen.prototype.createWiregenImages = function(session) { targetFile = path.join(session.workingDir, "wiregen", "output", "svg_hypothesis", fname); fs.writeFileSync(targetFile, fs.readFileSync(sourceFile)); }); + console.log('# ending wiregen'); resolve(session); } else{ From 66fefc2ebb49eb06f2f678cb3da1a20cd53bc8f1 Mon Sep 17 00:00:00 2001 From: Ulrich Krispel Date: Thu, 3 Dec 2015 16:54:01 +0100 Subject: [PATCH 2/6] prepare for automated elecdetect evaluation --- src/api/controllers/RiseController.js | 12 +- src/bindings/wiregen/index.js | 187 ++++++++++++++------------ 2 files changed, 111 insertions(+), 88 deletions(-) diff --git a/src/api/controllers/RiseController.js b/src/api/controllers/RiseController.js index 8e4e5d9..3941752 100644 --- a/src/api/controllers/RiseController.js +++ b/src/api/controllers/RiseController.js @@ -194,7 +194,7 @@ function createInputSymbolList(session) { }); } console.log("imported " + session[category].length + " " + category + " symbols."); - console.log(JSON.stringify(session[category])); + //console.log(JSON.stringify(session[category])); }); session.wiregenPath = path.join(session.workingDir, 'wiregen'); @@ -544,8 +544,16 @@ module.exports = { }).status(200); }); }); - } + }, + + evaluateElecdetect: function(req, res, next) + { + var session = prepareSession(req.body.e57master); + var walljson = JSON.parse(fs.readFileSync(session.wallfile, "utf8")); + + prepareWiregen(session); + } }; diff --git a/src/bindings/wiregen/index.js b/src/bindings/wiregen/index.js index c08f6fc..223fc66 100644 --- a/src/bindings/wiregen/index.js +++ b/src/bindings/wiregen/index.js @@ -8,25 +8,19 @@ var Wiregen = module.exports = function() { //this.session = session; }; -Wiregen.prototype.importDetections = function(session) { - session.wiregenInput = []; - session.Sockets = []; - session.Switches = []; - - if (session.config.wiregen.roots) { - session.Roots = session.config.wiregen.roots; - } else { - session.Roots = []; - } - - var promises = []; - - if (session.useGroundtruth) +function importGroundtruthSymbols(session) +{ + var symbols = { + 'Sockets' : [], + 'Switches' : [], + 'Roots' : [] + }; + + console.log('[Wiregen::importGroundtruth]'); + + var walljson = JSON.parse(fs.readFileSync(session.wallfile, "utf8")); + for (var i=0; i Date: Mon, 7 Dec 2015 16:25:06 +0100 Subject: [PATCH 3/6] groundtruth evaluation for elecdetect --- src/api/controllers/RiseController.js | 111 +++++++++++++++++++++++++- src/bindings/wiregen/index.js | 22 +++-- 2 files changed, 124 insertions(+), 9 deletions(-) diff --git a/src/api/controllers/RiseController.js b/src/api/controllers/RiseController.js index 3941752..927ea5a 100644 --- a/src/api/controllers/RiseController.js +++ b/src/api/controllers/RiseController.js @@ -549,10 +549,117 @@ module.exports = { evaluateElecdetect: function(req, res, next) { var session = prepareSession(req.body.e57master); + var wiregen = new Wiregen(); + prepareWiregen(session); + var symbol_elecdetect = wiregen.importElecdetectSymbols(session); + var symbol_groundtruth = wiregen.importGroundtruthSymbols(session); + + console.log('###################### Elecdetect Evaluation ###############'); + var symbol_statistics = function(m,s) { + console.log('***' + m + '***'); + for (var i in s) { + console.log(i + ":" + s[i].length + " symbols."); + } + }; + symbol_statistics('Elecdetect', symbol_elecdetect); + symbol_statistics('Groundtruth', symbol_groundtruth); + + // compare category GT (groundtruth) vs + // category D (detected) in terms of + // comparison per wall + // - matches (overlapping symbols) + // - false positives (object in D but not in GT) + // - false negatives (object in GT but not in D) + var compare_category = function(GT, D) + { + // build wall index + var wallIndex = function(symbols) + { + var wi = {}; + for (var i = 0, ie = symbols.length; i= 0.9) + { + console.log('overlap detected: AL:' + A.left + ' AW:' + A.width + ' AT:' + A.top + ' AH' + A.height + + ' BL:' + B.left + ' BW:' + B.width + ' BT:' + B.top + ' BH' + B.height); + console.log('area a: ' + areaA + ' area b:' + areaB + ' relsize:' + Math.abs(areaA/areaB - 1.0) + ' area overlap:' + area); + console.log((area / areaA) + ' => match!'); + match_gt[i_gt] = '1'; + match_d[i_d] = '1'; + } + } + } + } - var walljson = JSON.parse(fs.readFileSync(session.wallfile, "utf8")); + // count matches and fals positives/negatives + if (wall_gt[wallid]) + for (var i_gt = 0, i_gte = wall_gt[wallid].length; i_gt < i_gte; ++i_gt) + { + if (match_gt[i_gt] == '1') { result.match += 1; } + else { result.false_negative +=1; } // gt but not detected + } - prepareWiregen(session); + for (var i_d = 0, i_de = wall_d[wallid].length; i_d < i_de; ++i_d) + { + if (match_d[i_d] != '1') { result.false_positive += 1; } // detection not present in gt + } + + }); + + + return result; + } + + console.log('GT Sockets:' + JSON.stringify(symbol_groundtruth.Sockets)); + console.log('D Sockets:' + JSON.stringify(symbol_elecdetect.Sockets)); + var sockets = compare_category(symbol_groundtruth.Sockets, symbol_elecdetect.Sockets); + console.log(JSON.stringify(sockets)); + var switches = compare_category(symbol_groundtruth.Switches, symbol_elecdetect.Switches); + console.log(JSON.stringify(switches)); } diff --git a/src/bindings/wiregen/index.js b/src/bindings/wiregen/index.js index 223fc66..27feca8 100644 --- a/src/bindings/wiregen/index.js +++ b/src/bindings/wiregen/index.js @@ -4,10 +4,6 @@ var spawn = require('child_process').spawn, fs = require('fs'), xml2js = require('xml2js'); -var Wiregen = module.exports = function() { - //this.session = session; -}; - function importGroundtruthSymbols(session) { var symbols = { @@ -30,7 +26,9 @@ function importGroundtruthSymbols(session) try { hasSVG = fs.lstatSync(svgfilename).isFile(); - } catch (err) { } + } catch (err) { + console.log('file ' + svgfilename + ' could not be opened.'); + } if (hasSVG) { @@ -54,6 +52,9 @@ function importGroundtruthSymbols(session) var transform = RE.exec(rect.$.transform); var sx = Number(transform[1]); var sy = Number(transform[2]); + } else { + sx = 1.0; + sy = 1.0; } var item = { @@ -103,6 +104,7 @@ function importElecdetectSymbols(session) if (n.file.substr(-4) === '.xml') { var f = path.join(session.elecdetecResults, n.file); + console.log('importing from ' + f); var contents = fs.readFileSync(f, 'utf-8'); var parser = new xml2js.Parser(); @@ -125,8 +127,6 @@ function importElecdetectSymbols(session) "wallid": wallid } }; - //console.log('new item' + object.label); - if (object.label == '1') { item.label = 'SOCKET'; symbols.Sockets.push(item); @@ -135,6 +135,8 @@ function importElecdetectSymbols(session) item.label = 'SWITCH'; symbols.Switches.push(item); } + console.log('new item' + JSON.stringify(item) ); + } } }); @@ -144,6 +146,12 @@ function importElecdetectSymbols(session) return symbols; } +var Wiregen = module.exports = function() { +}; + +Wiregen.prototype.importElecdetectSymbols = importElecdetectSymbols; +Wiregen.prototype.importGroundtruthSymbols = importGroundtruthSymbols; + Wiregen.prototype.importDetections = function(session) { return new Promise(function(resolve, reject) { session.wiregenInput = []; From ce90af8005e2b421bdd20d72c5ed084888528154 Mon Sep 17 00:00:00 2001 From: Ulrich Krispel Date: Mon, 7 Dec 2015 16:43:47 +0100 Subject: [PATCH 4/6] fix evaluation import --- src/api/controllers/RiseController.js | 6 +++--- src/bindings/wiregen/index.js | 13 +++++++++---- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/api/controllers/RiseController.js b/src/api/controllers/RiseController.js index 927ea5a..8dd2b00 100644 --- a/src/api/controllers/RiseController.js +++ b/src/api/controllers/RiseController.js @@ -622,14 +622,14 @@ module.exports = { if ( (left < right) && (top < bottom) && Math.abs(areaA/areaB - 1.0)<0.1 ) { var area = (right-left) * (bottom-top); - if ((area / areaA) >= 0.9) - { console.log('overlap detected: AL:' + A.left + ' AW:' + A.width + ' AT:' + A.top + ' AH' + A.height + ' BL:' + B.left + ' BW:' + B.width + ' BT:' + B.top + ' BH' + B.height); console.log('area a: ' + areaA + ' area b:' + areaB + ' relsize:' + Math.abs(areaA/areaB - 1.0) + ' area overlap:' + area); + if ((area / areaA) >= 0.9) + { console.log((area / areaA) + ' => match!'); match_gt[i_gt] = '1'; - match_d[i_d] = '1'; + match_d[i_d] = '1'; } } } diff --git a/src/bindings/wiregen/index.js b/src/bindings/wiregen/index.js index 27feca8..a441789 100644 --- a/src/bindings/wiregen/index.js +++ b/src/bindings/wiregen/index.js @@ -56,13 +56,18 @@ function importGroundtruthSymbols(session) sx = 1.0; sy = 1.0; } + // parse width + var RE = /stroke-width:([^;]*);/gi; + var sw = RE.exec(rect.$.style); + var strokewidth = Number(sw[1]); + console.log(strokewidth); var item = { "attributes": { - "left": sx*Number(rect.$.x), - "top": sy*Number(rect.$.y), - "width": Number(rect.$.width), - "height": Number(rect.$.height), + "left": sx*Number(rect.$.x)-strokewidth, + "top": sy*Number(rect.$.y)-strokewidth, + "width": Number(rect.$.width)+2*strokewidth, + "height": Number(rect.$.height)+2*strokewidth, "wallid": wall.attributes.id } }; From c9c620a793f97829ca9f0f9d3ad76ccc964e1059 Mon Sep 17 00:00:00 2001 From: Martin Hecher Date: Wed, 9 Dec 2015 11:17:11 +0100 Subject: [PATCH 5/6] Update README.md --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index dc191b4..24d79a4 100644 --- a/README.md +++ b/README.md @@ -44,8 +44,9 @@ Our recommended stack is to install DURAARK on a Docker-compatible Linux system On the host you want to deploy the service execute the following steps (assuming that Docker and Docker Compose are installed and working): ```js -> git clone https://github.com/DURAARK/duraark-geometricenrichment.git +> git clone --recursive https://github.com/DURAARK/duraark-geometricenrichment.git > cd duraark-geometricenrichment +> sudo mkdir -p /duraark-storage/sessions > docker-compose up -d ``` @@ -58,9 +59,10 @@ The files you want to use have to be put into the folder **/tmp/duraark/files**. To setup the environment follow these steps: ```js -> git clone https://github.com/DURAARK/duraark-geometricenrichment.git +> git clone --recursive https://github.com/DURAARK/duraark-geometricenrichment.git > cd duraark-geometricenrichment > npm install +> mkdir -p /duraark-storage/sessions > docker-compose -f devenv-compose.yml build > docker-compose -f devenv-compose.yml up -d ``` From e15b5205e86c11bc480b0d2a9a3e2918e3759de5 Mon Sep 17 00:00:00 2001 From: Martin Hecher Date: Wed, 9 Dec 2015 11:23:48 +0100 Subject: [PATCH 6/6] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 24d79a4..1545272 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,9 @@ Information on the provided functionalities can be found in the reports * [D5.4 Shape grammars for almost invisible structures Software prototype v2](http://duraark.eu/wp-content/uploads/2015/08/DURAARK_D5.5.4.pdf) * [D2.5 Software prototype v2, Section 4.4](http://duraark.eu/wp-content/uploads/2015/08/DURAARK_D2_5_final.pdf) (overview) +### Usage + +Usage documentation is available [here](https://github.com/DURAARK/duraark-geometricenrichment/wiki). ### Dependencies The service depends on the following DURAARK components: