diff --git a/examples/test.js b/examples/test.js new file mode 100644 index 0000000..5513781 --- /dev/null +++ b/examples/test.js @@ -0,0 +1,6 @@ +var cv = require('../lib/opencv'); + +var mat = new cv.Matrix(1, 2, cv.Constants.CV_8U, [1]); +var row = mat.pixelRow(0); +console.log("mat: " + row[0] + row[1]); + diff --git a/src/Matrix.cc b/src/Matrix.cc index 97e890d..e0026a7 100755 --- a/src/Matrix.cc +++ b/src/Matrix.cc @@ -1893,7 +1893,7 @@ NAN_METHOD(Matrix::ConvertTo) { // param 3 - beta double beta = 0; if (info.Length() >= 4) { - DOUBLE_FROM_ARGS(alpha, 3); + DOUBLE_FROM_ARGS(beta, 3); } self->mat.convertTo(dest->mat, rtype, alpha, beta); @@ -2435,11 +2435,13 @@ NAN_METHOD(Matrix::Reshape) { JSTHROW("Invalid number of arguments"); } - cv::Mat res = self->mat.reshape(cn, rows); - ~self->mat; - self->mat = res; + Local img_to_return = + Nan::New(Matrix::constructor)->GetFunction()->NewInstance(); + Matrix *img = Nan::ObjectWrap::Unwrap(img_to_return); - return; + img->mat = self->mat.reshape(cn, rows); + + info.GetReturnValue().Set(img_to_return); } NAN_METHOD(Matrix::Release) { diff --git a/test/.unit.js.swp b/test/.unit.js.swp new file mode 100644 index 0000000..b3cd16c Binary files /dev/null and b/test/.unit.js.swp differ diff --git a/test/unit.js b/test/unit.js index 3c8a8ee..50d92a8 100755 --- a/test/unit.js +++ b/test/unit.js @@ -53,7 +53,9 @@ test('Point', function(t){ test('Matrix constructor', function(assert){ assert.ok(cv.Matrix); assert.ok(new cv.Matrix); - assert.ok(new cv.Matrix(1,2)); + assert.ok(new cv.Matrix(1, 2)); + assert.ok(new cv.Matrix(1, 2, cv.Constants.CV_8U)); + assert.ok(new cv.Matrix(1, 2, cv.Constants.CV_8U, [1])); assert.end() }) @@ -91,9 +93,43 @@ test('Matrix accessors', function(assert){ assert.equal(new cv.Matrix().empty(), true); + mat = new cv.Matrix(1, 2, cv.Constants.CV_8UC3, [1, 2, 3]); + assert.deepEqual(mat.pixelRow(0), [1, 2, 3, 1, 2, 3]); + assert.end() }) +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); + + // reshape + mat = new cv.Matrix(75, 75, cv.Constants.CV_8UC1); + matNew = mat.reshape(1, 1); + assert.equal(matNew.height(), 1); + assert.equal(matNew.width(), 5625); + + assert.end(); +}) + +test(".norm", function(assert){ + cv.readImage("./examples/files/coin1.jpg", function(err, im) { + cv.readImage("./examples/files/coin2.jpg", function(err, im2){ + assert.ok(im); + assert.ok(im2); + + var errorL2 = im.norm(im2, cv.Constants.NORM_L2); + assert.equal(errorL2, 7295.591339980605); + + errorL2 = im.norm(im, cv.Constants.NORM_L2); + assert.equal(errorL2, 0); + assert.end(); + }); + }); +}) test("Matrix toBuffer", function(assert){ var buf = fs.readFileSync('./examples/files/mona.png') @@ -105,8 +141,6 @@ test("Matrix toBuffer", function(assert){ }) }) - - test("Matrix toBuffer Async", function(assert){ var buf = fs.readFileSync('./examples/files/mona.png')