diff --git a/src/Matrix.cc b/src/Matrix.cc index 7fda60f..46be360 100755 --- a/src/Matrix.cc +++ b/src/Matrix.cc @@ -68,6 +68,7 @@ void Matrix::Init(Local target) { Nan::SetPrototypeMethod(ctor, "dct", Dct); Nan::SetPrototypeMethod(ctor, "idct", Idct); Nan::SetPrototypeMethod(ctor, "addWeighted", AddWeighted); + Nan::SetPrototypeMethod(ctor, "add", Add); Nan::SetPrototypeMethod(ctor, "bitwiseXor", BitwiseXor); Nan::SetPrototypeMethod(ctor, "bitwiseNot", BitwiseNot); Nan::SetPrototypeMethod(ctor, "bitwiseAnd", BitwiseAnd); @@ -1342,6 +1343,29 @@ NAN_METHOD(Matrix::AddWeighted) { info.GetReturnValue().Set(Nan::Null()); } +NAN_METHOD(Matrix::Add) { + Nan::HandleScope scope; + + Matrix *self = Nan::ObjectWrap::Unwrap(info.This()); + int cols = self->mat.cols; + int rows = self->mat.rows; + + Matrix *src1 = Nan::ObjectWrap::Unwrap(info[0]->ToObject()); + + Local out = Nan::New(Matrix::constructor)->GetFunction()->NewInstance(); + Matrix *m_out = Nan::ObjectWrap::Unwrap(out); + m_out->mat.create(cols, rows, self->mat.type()); + + try { + cv::add(self->mat, src1->mat, m_out->mat); + } catch(cv::Exception& e ) { + const char* err_msg = e.what(); + Nan::ThrowError(err_msg); + } + + info.GetReturnValue().Set(out); +} + NAN_METHOD(Matrix::BitwiseXor) { Nan::HandleScope scope; diff --git a/src/Matrix.h b/src/Matrix.h index cf9e65d..7aaf473 100755 --- a/src/Matrix.h +++ b/src/Matrix.h @@ -69,8 +69,9 @@ public: JSFUNC(Ptr) JSFUNC(AbsDiff) JSFUNC(Dct) - JSFUNC(Idct) + JSFUNC(Idct) JSFUNC(AddWeighted) + JSFUNC(Add) JSFUNC(BitwiseXor) JSFUNC(BitwiseNot) JSFUNC(BitwiseAnd)