From 081a36a9959a1e4ddc0539c4b3af7b2ddbbd25ae Mon Sep 17 00:00:00 2001 From: Pierre Colle Date: Tue, 8 Nov 2016 12:49:56 +0100 Subject: [PATCH 1/4] get experimentations --- examples/mat-get.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 examples/mat-get.js diff --git a/examples/mat-get.js b/examples/mat-get.js new file mode 100644 index 0000000..f27cbe0 --- /dev/null +++ b/examples/mat-get.js @@ -0,0 +1,30 @@ +var cv = require('../lib/opencv'); + +cv.readImage("./files/mona.png", function(err, orig) { + if (err) throw err; + + var chan1 = orig.split()[0]; + + var floatMatrix = new cv.Matrix(); + var chan1Back = new cv.Matrix(); + + chan1.convertTo(floatMatrix, cv.Constants.CV_32F); + floatMatrix.convertTo(chan1Back, cv.Constants.CV_8U); + + var rowId = 0; + var colId = 0; + + console.log(orig.get(rowId,colId), orig.pixel(rowId, colId)); + // ACTUAL : => -8.425768939900947e-273 [25, 51, 57] + // EXPECTED : => [25, 51, 57] (this is R : 57 G : 51 and B : 25) + console.log(chan1.get(rowId,colId), chan1.pixel(rowId, colId)); + // ACTUAL => 1.76244473776441e-105 36 + // EXPECTED => 154 + console.log(floatMatrix.get(rowId,colId), floatMatrix.pixel(rowId, colId)); + // ACTUAL => 481036405168 + // EXPECTED => 154.0 + console.log(chan1Back.get(rowId,colId), chan1Back.pixel(rowId, colId)); + // ACTUAL => 1.76244473776441e-105 + // EXPECTED => 154 + +}); From 749e27aaf951563082aa533907c0517021b9f194 Mon Sep 17 00:00:00 2001 From: Pierre Colle Date: Tue, 8 Nov 2016 14:33:38 +0100 Subject: [PATCH 2/4] change to get from CV_32F Matrix --- src/Matrix.cc | 3 +++ test/unit.js | 1 + 2 files changed, 4 insertions(+) diff --git a/src/Matrix.cc b/src/Matrix.cc index d95ab1e..72d54bd 100755 --- a/src/Matrix.cc +++ b/src/Matrix.cc @@ -208,6 +208,9 @@ double Matrix::DblGet(cv::Mat mat, int i, int j) { case CV_64FC1: val = mat.at(i, j); break; + case CV_32FC1: + val = mat.at(i, j); + break; default: val = mat.at(i, j); break; diff --git a/test/unit.js b/test/unit.js index c28ad04..2fc9ce4 100755 --- a/test/unit.js +++ b/test/unit.js @@ -105,6 +105,7 @@ test('Matrix functions', function(assert) { var matNew = new cv.Matrix(75, 75, cv.Constants.CV_8U); mat.convertTo(matNew, cv.Constants.CV_8U, 2, 1); assert.equal(matNew.pixel(0, 0), 5); + assert.equal(mat.get(0, 0), 5) // reshape mat = new cv.Matrix(75, 75, cv.Constants.CV_8UC1); From 9a90480d9b4885d9224d2fd783f224bd7194981b Mon Sep 17 00:00:00 2001 From: Pierre Colle Date: Tue, 8 Nov 2016 14:41:54 +0100 Subject: [PATCH 3/4] adding unit test to get on Float --- test/unit.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/unit.js b/test/unit.js index 2fc9ce4..97767f3 100755 --- a/test/unit.js +++ b/test/unit.js @@ -103,9 +103,10 @@ test('Matrix functions', function(assert) { // convertTo var mat = new cv.Matrix(75, 75, cv.Constants.CV_32F, [2.0]); var matNew = new cv.Matrix(75, 75, cv.Constants.CV_8U); - mat.convertTo(matNew, cv.Constants.CV_8U, 2, 1); - assert.equal(matNew.pixel(0, 0), 5); - assert.equal(mat.get(0, 0), 5) + var alpha = 2; + var beta = 1; + mat.convertTo(matNew, cv.Constants.CV_8U, alpha, beta); + assert.equal(matNew.pixel(0, 0), mat.get(0, 0)*alpha + beta); // reshape mat = new cv.Matrix(75, 75, cv.Constants.CV_8UC1); From a764ff83b5d2c515969cd50683c68fee1a8f9c07 Mon Sep 17 00:00:00 2001 From: Pierre Colle Date: Tue, 8 Nov 2016 14:45:24 +0100 Subject: [PATCH 4/4] examples/mat-get.js not useful anymore, now unit test has been written --- examples/mat-get.js | 30 ------------------------------ 1 file changed, 30 deletions(-) delete mode 100644 examples/mat-get.js diff --git a/examples/mat-get.js b/examples/mat-get.js deleted file mode 100644 index f27cbe0..0000000 --- a/examples/mat-get.js +++ /dev/null @@ -1,30 +0,0 @@ -var cv = require('../lib/opencv'); - -cv.readImage("./files/mona.png", function(err, orig) { - if (err) throw err; - - var chan1 = orig.split()[0]; - - var floatMatrix = new cv.Matrix(); - var chan1Back = new cv.Matrix(); - - chan1.convertTo(floatMatrix, cv.Constants.CV_32F); - floatMatrix.convertTo(chan1Back, cv.Constants.CV_8U); - - var rowId = 0; - var colId = 0; - - console.log(orig.get(rowId,colId), orig.pixel(rowId, colId)); - // ACTUAL : => -8.425768939900947e-273 [25, 51, 57] - // EXPECTED : => [25, 51, 57] (this is R : 57 G : 51 and B : 25) - console.log(chan1.get(rowId,colId), chan1.pixel(rowId, colId)); - // ACTUAL => 1.76244473776441e-105 36 - // EXPECTED => 154 - console.log(floatMatrix.get(rowId,colId), floatMatrix.pixel(rowId, colId)); - // ACTUAL => 481036405168 - // EXPECTED => 154.0 - console.log(chan1Back.get(rowId,colId), chan1Back.pixel(rowId, colId)); - // ACTUAL => 1.76244473776441e-105 - // EXPECTED => 154 - -});