diff --git a/src/Matrix.cc b/src/Matrix.cc index 87dec24..b1a1b39 100755 --- a/src/Matrix.cc +++ b/src/Matrix.cc @@ -109,6 +109,7 @@ void Matrix::Init(Local target) { Nan::SetPrototypeMethod(ctor, "shift", Shift); Nan::SetPrototypeMethod(ctor, "reshape", Reshape); Nan::SetPrototypeMethod(ctor, "release", Release); + Nan::SetPrototypeMethod(ctor, "subtract", Subtract); target->Set(Nan::New("Matrix").ToLocalChecked(), ctor->GetFunction()); }; @@ -2569,3 +2570,17 @@ NAN_METHOD(Matrix::Release) { return; } + +NAN_METHOD(Matrix::Subtract) { + SETUP_FUNCTION(Matrix) + + if (info.Length() < 1) { + Nan::ThrowTypeError("Invalid number of arguments"); + } + + Matrix *other = Nan::ObjectWrap::Unwrap(info[0]->ToObject()); + + self->mat -= other->mat; + + return; +} diff --git a/src/Matrix.h b/src/Matrix.h index 042c86d..e000737 100755 --- a/src/Matrix.h +++ b/src/Matrix.h @@ -125,6 +125,8 @@ public: JSFUNC(Reshape) JSFUNC(Release) + + JSFUNC(Subtract) /* static Handle Val(const Arguments& info); static Handle RowRange(const Arguments& info); diff --git a/test/unit.js b/test/unit.js index fa82735..a6312b2 100755 --- a/test/unit.js +++ b/test/unit.js @@ -341,6 +341,15 @@ test('Native Matrix', function(assert) { assert.end(); }) +test('Subtract', function(assert) { + var a = new cv.Matrix.Zeros(1,1); + a.set(0, 0, 3); + var b = new cv.Matrix.Zeros(1,1); + b.set(0, 0, 1); + a.subtract(b); + assert.deepEqual(a.get(0, 0), 2); + assert.end(); +}); // Test the examples folder. require('./examples')()