From 7eaa429eae06299d0917d431ab521e4925ac1d16 Mon Sep 17 00:00:00 2001 From: Alexander Milchev Date: Wed, 23 Mar 2016 14:58:20 +0200 Subject: [PATCH 1/3] Add inpaint function --- src/Matrix.cc | 35 ++++++++++++++++++++++++++++------- src/Matrix.h | 2 ++ 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/Matrix.cc b/src/Matrix.cc index e0df89ca..7cfc6776 100755 --- a/src/Matrix.cc +++ b/src/Matrix.cc @@ -3,6 +3,7 @@ #include "OpenCV.h" #include #include +#include Nan::Persistent Matrix::constructor; @@ -109,6 +110,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); target->Set(Nan::New("Matrix").ToLocalChecked(), ctor->GetFunction()); }; @@ -2269,19 +2271,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 @@ -2569,3 +2571,22 @@ 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()); + + 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); +} diff --git a/src/Matrix.h b/src/Matrix.h index 042c86da..d363a88b 100755 --- a/src/Matrix.h +++ b/src/Matrix.h @@ -125,6 +125,8 @@ class Matrix: public node_opencv::Matrix{ JSFUNC(Reshape) JSFUNC(Release) + + JSFUNC(Inpaint) /* static Handle Val(const Arguments& info); static Handle RowRange(const Arguments& info); From 62a5794cb2e302d169af7f3b4fad2f38fee95e4c Mon Sep 17 00:00:00 2001 From: Alexander Milchev Date: Tue, 29 Mar 2016 11:07:53 +0300 Subject: [PATCH 2/3] Convert argument mask to CV_8U when inpainting --- src/Matrix.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Matrix.cc b/src/Matrix.cc index 7cfc6776..8595f8da 100755 --- a/src/Matrix.cc +++ b/src/Matrix.cc @@ -2580,6 +2580,7 @@ NAN_METHOD(Matrix::Inpaint) { } 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); From 3f4042edadd105e0ce9a687eafbb3bb066f641ff Mon Sep 17 00:00:00 2001 From: Alexander Milchev Date: Wed, 18 May 2016 17:08:13 +0300 Subject: [PATCH 3/3] Fix minor merge mistake --- src/Matrix.cc | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Matrix.cc b/src/Matrix.cc index 552b27d8..715e4296 100755 --- a/src/Matrix.cc +++ b/src/Matrix.cc @@ -111,11 +111,8 @@ void Matrix::Init(Local target) { Nan::SetPrototypeMethod(ctor, "shift", Shift); Nan::SetPrototypeMethod(ctor, "reshape", Reshape); Nan::SetPrototypeMethod(ctor, "release", Release); -<<<<<<< HEAD Nan::SetPrototypeMethod(ctor, "inpaint", Inpaint); -======= Nan::SetPrototypeMethod(ctor, "subtract", Subtract); ->>>>>>> df9959ae7dbfa57fb39147dcb745e67775154b11 target->Set(Nan::New("Matrix").ToLocalChecked(), ctor->GetFunction()); };