Merge pull request #395 from andreasgal/subtract

add subtract() to Matrix
This commit is contained in:
Michael Vines 2016-04-21 20:57:47 -07:00
commit a3db0acb0a
3 changed files with 26 additions and 0 deletions

View File

@ -109,6 +109,7 @@ void Matrix::Init(Local<Object> target) {
Nan::SetPrototypeMethod(ctor, "shift", Shift); Nan::SetPrototypeMethod(ctor, "shift", Shift);
Nan::SetPrototypeMethod(ctor, "reshape", Reshape); Nan::SetPrototypeMethod(ctor, "reshape", Reshape);
Nan::SetPrototypeMethod(ctor, "release", Release); Nan::SetPrototypeMethod(ctor, "release", Release);
Nan::SetPrototypeMethod(ctor, "subtract", Subtract);
target->Set(Nan::New("Matrix").ToLocalChecked(), ctor->GetFunction()); target->Set(Nan::New("Matrix").ToLocalChecked(), ctor->GetFunction());
}; };
@ -2569,3 +2570,17 @@ NAN_METHOD(Matrix::Release) {
return; return;
} }
NAN_METHOD(Matrix::Subtract) {
SETUP_FUNCTION(Matrix)
if (info.Length() < 1) {
Nan::ThrowTypeError("Invalid number of arguments");
}
Matrix *other = Nan::ObjectWrap::Unwrap<Matrix>(info[0]->ToObject());
self->mat -= other->mat;
return;
}

View File

@ -125,6 +125,8 @@ public:
JSFUNC(Reshape) JSFUNC(Reshape)
JSFUNC(Release) JSFUNC(Release)
JSFUNC(Subtract)
/* /*
static Handle<Value> Val(const Arguments& info); static Handle<Value> Val(const Arguments& info);
static Handle<Value> RowRange(const Arguments& info); static Handle<Value> RowRange(const Arguments& info);

View File

@ -341,6 +341,15 @@ test('Native Matrix', function(assert) {
assert.end(); 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. // Test the examples folder.
require('./examples')() require('./examples')()