From 416fbd100efaeb22b3c5810a4dc7095bacf80652 Mon Sep 17 00:00:00 2001 From: Pierre Colle Date: Tue, 5 Sep 2017 17:36:48 +0200 Subject: [PATCH] add compare --- src/Constants.cc | 7 +++++++ src/Matrix.cc | 26 ++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/Constants.cc b/src/Constants.cc index b2ab548..462b134 100644 --- a/src/Constants.cc +++ b/src/Constants.cc @@ -101,6 +101,13 @@ void Constants::Init(Local target) { CONST_INT(CV_DIST_MASK_5); CONST_INT(CV_DIST_MASK_PRECISE); + CONST_ENUM(CMP_EQ) + CONST_ENUM(CMP_GT) + CONST_ENUM(CMP_GE) + CONST_ENUM(CMP_LT) + CONST_ENUM(CMP_LE) + CONST_ENUM(CMP_NE) + target->Set(Nan::New("TERM_CRITERIA_EPS").ToLocalChecked(), Nan::New((int)cv::TermCriteria::EPS)); target->Set(Nan::New("TERM_CRITERIA_COUNT").ToLocalChecked(), Nan::New((int)cv::TermCriteria::COUNT)); diff --git a/src/Matrix.cc b/src/Matrix.cc index 81a6ba3..80aec83 100755 --- a/src/Matrix.cc +++ b/src/Matrix.cc @@ -116,6 +116,7 @@ void Matrix::Init(Local target) { Nan::SetPrototypeMethod(ctor, "reshape", Reshape); Nan::SetPrototypeMethod(ctor, "release", Release); Nan::SetPrototypeMethod(ctor, "subtract", Subtract); + Nan::SetPrototypeMethod(ctor, "compare", Compare); target->Set(Nan::New("Matrix").ToLocalChecked(), ctor->GetFunction()); }; @@ -2835,3 +2836,28 @@ NAN_METHOD(Matrix::Subtract) { return; } + +NAN_METHOD(Matrix::Compare) { + SETUP_FUNCTION(Matrix) + + if (info.Length() < 2) { + Nan::ThrowTypeError("Invalid number of arguments"); + } + Matrix *other = Nan::ObjectWrap::Unwrap(info[0]->ToObject()); + + int cmpop = info[1]->IntegerValue(); + + int width = self->mat.size().width; + int height = self->mat.size().height; + + cv::Mat res = cv::Mat(width, height, CV_8UC1); + + cv::compare(self->mat, other->mat, res, cmpop); + + Local out = Nan::NewInstance(Nan::GetFunction(Nan::New(Matrix::constructor)).ToLocalChecked()).ToLocalChecked(); + Matrix *m_out = Nan::ObjectWrap::Unwrap(out); + m_out->mat = res; + + info.GetReturnValue().Set(out); + return; +}