From b5a078a631c6b4a25f65b85de7df611ee47d8289 Mon Sep 17 00:00:00 2001 From: Patrick Childers Date: Fri, 13 Apr 2018 09:11:49 -0400 Subject: [PATCH 1/2] Add Div/Pow matrix functions. --- src/Matrix.cc | 31 +++++++++++++++++++++++++++++++ src/Matrix.h | 3 +++ 2 files changed, 34 insertions(+) diff --git a/src/Matrix.cc b/src/Matrix.cc index 8cd71c3..716ddb7 100755 --- a/src/Matrix.cc +++ b/src/Matrix.cc @@ -124,6 +124,8 @@ void Matrix::Init(Local target) { Nan::SetPrototypeMethod(ctor, "subtract", Subtract); Nan::SetPrototypeMethod(ctor, "compare", Compare); Nan::SetPrototypeMethod(ctor, "mul", Mul); + Nan::SetPrototypeMethod(ctor, "div", Div); + Nan::SetPrototypeMethod(ctor, "pow", Pow); target->Set(Nan::New("Matrix").ToLocalChecked(), ctor->GetFunction()); }; @@ -3154,3 +3156,32 @@ NAN_METHOD(Matrix::Mul) { info.GetReturnValue().Set(out); return; } + +NAN_METHOD(Matrix::Div) { + SETUP_FUNCTION(Matrix) + + if (info.Length() < 1) { + Nan::ThrowTypeError("Invalid number of arguments"); + } + + Matrix *other = Nan::ObjectWrap::Unwrap(info[0]->ToObject()); + + cv::divide(self->mat, other->mat, self->mat); + + return; +} + +NAN_METHOD(Matrix::Pow) { + SETUP_FUNCTION(Matrix) + + if (info.Length() < 1) { + Nan::ThrowTypeError("Invalid number of arguments"); + } + + double power = info[0]->NumberValue(); + + cv::pow(self->mat, power, self->mat); + + return; +} + diff --git a/src/Matrix.h b/src/Matrix.h index 336b9fc..61f62a3 100755 --- a/src/Matrix.h +++ b/src/Matrix.h @@ -149,6 +149,9 @@ public: JSFUNC(Subtract) JSFUNC(Compare) JSFUNC(Mul) + JSFUNC(Div) + JSFUNC(Pow) + /* static Handle Val(const Arguments& info); static Handle RowRange(const Arguments& info); From a9f799004d3ab489e1a1fc8868fab76dced2b414 Mon Sep 17 00:00:00 2001 From: Patrick Childers Date: Fri, 13 Apr 2018 12:42:47 -0400 Subject: [PATCH 2/2] Add CV_BGRA2BGR format conversion. --- src/Matrix.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Matrix.cc b/src/Matrix.cc index 716ddb7..b7884e0 100755 --- a/src/Matrix.cc +++ b/src/Matrix.cc @@ -2485,6 +2485,8 @@ NAN_METHOD(Matrix::CvtColor) { iTransform = CV_BayerGR2BGR; } else if (!strcmp(sTransform, "CV_BGR2RGB")) { iTransform = CV_BGR2RGB; + } else if (!strcmp(sTransform, "CV_BGRA2BGR")) { + iTransform = CV_BGRA2BGR; } else { iTransform = 0; // to avoid compiler warning Nan::ThrowTypeError("Conversion code is unsupported");