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 + +}); 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..97767f3 100755 --- a/test/unit.js +++ b/test/unit.js @@ -103,8 +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); + 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);