Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 29 additions & 7 deletions src/Matrix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "OpenCV.h"
#include <string.h>
#include <nan.h>
#include <opencv2/photo/photo.hpp>

Nan::Persistent<FunctionTemplate> Matrix::constructor;

Expand Down Expand Up @@ -110,6 +111,7 @@ void Matrix::Init(Local<Object> 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());
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<Matrix>(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<Matrix>(img_to_return);
self->mat.copyTo(img->mat);

info.GetReturnValue().Set(img_to_return);
}

NAN_METHOD(Matrix::Subtract) {
SETUP_FUNCTION(Matrix)

Expand Down
2 changes: 2 additions & 0 deletions src/Matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ class Matrix: public node_opencv::Matrix{

JSFUNC(Release)

JSFUNC(Inpaint)

JSFUNC(Subtract)
/*
static Handle<Value> Val(const Arguments& info);
Expand Down