diff --git a/src/Matrix.cc b/src/Matrix.cc index 45f02363..715e4296 100755 --- a/src/Matrix.cc +++ b/src/Matrix.cc @@ -3,6 +3,7 @@ #include "OpenCV.h" #include #include +#include Nan::Persistent Matrix::constructor; @@ -110,6 +111,7 @@ void Matrix::Init(Local target) { Nan::SetPrototypeMethod(ctor, "shift", Shift); Nan::SetPrototypeMethod(ctor, "reshape", Reshape); Nan::SetPrototypeMethod(ctor, "release", Release); + Nan::SetPrototypeMethod(ctor, "inpaint", Inpaint); Nan::SetPrototypeMethod(ctor, "subtract", Subtract); target->Set(Nan::New("Matrix").ToLocalChecked(), ctor->GetFunction()); @@ -2271,19 +2273,19 @@ NAN_METHOD(Matrix::MatchTemplate) { int method = (info.Length() < 2) ? (int)cv::TM_CCORR_NORMED : info[1]->Uint32Value(); cv::matchTemplate(self->mat, templ, m_out->mat, method); cv::normalize(m_out->mat, m_out->mat, 0, 1, cv::NORM_MINMAX, -1, cv::Mat()); - double minVal; - double maxVal; - cv::Point minLoc; + double minVal; + double maxVal; + cv::Point minLoc; cv::Point maxLoc; cv::Point matchLoc; minMaxLoc(m_out->mat, &minVal, &maxVal, &minLoc, &maxLoc, cv::Mat()); - if(method == CV_TM_SQDIFF || method == CV_TM_SQDIFF_NORMED) { - matchLoc = minLoc; + if(method == CV_TM_SQDIFF || method == CV_TM_SQDIFF_NORMED) { + matchLoc = minLoc; } - else { - matchLoc = maxLoc; + else { + matchLoc = maxLoc; } //detected ROI @@ -2586,6 +2588,26 @@ NAN_METHOD(Matrix::Release) { return; } +NAN_METHOD(Matrix::Inpaint) { + SETUP_FUNCTION(Matrix) + + if (!info[0]->IsObject()) { + Nan::ThrowTypeError("The argument must be an object"); + } + + Matrix *mask = Nan::ObjectWrap::Unwrap(info[0]->ToObject()); + mask->mat.convertTo(mask->mat, CV_8U); + + cv::inpaint(self->mat, mask->mat, self->mat, 3, cv::INPAINT_TELEA); + + Local < Object > img_to_return = + Nan::New(Matrix::constructor)->GetFunction()->NewInstance(); + Matrix *img = Nan::ObjectWrap::Unwrap(img_to_return); + self->mat.copyTo(img->mat); + + info.GetReturnValue().Set(img_to_return); +} + NAN_METHOD(Matrix::Subtract) { SETUP_FUNCTION(Matrix) diff --git a/src/Matrix.h b/src/Matrix.h index 74cd100b..7d8beca8 100755 --- a/src/Matrix.h +++ b/src/Matrix.h @@ -127,6 +127,8 @@ class Matrix: public node_opencv::Matrix{ JSFUNC(Release) + JSFUNC(Inpaint) + JSFUNC(Subtract) /* static Handle Val(const Arguments& info);