From 5a306658df3f4df8b7e169f1a4a3d184bf61ebcf Mon Sep 17 00:00:00 2001 From: Fotios Lindiakos Date: Thu, 6 Oct 2016 15:12:33 -0400 Subject: [PATCH] Added copyMakeBorder function --- src/Matrix.cc | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ src/Matrix.h | 1 + 2 files changed, 50 insertions(+) diff --git a/src/Matrix.cc b/src/Matrix.cc index faff68d..b0da0af 100755 --- a/src/Matrix.cc +++ b/src/Matrix.cc @@ -20,6 +20,7 @@ void Matrix::Init(Local target) { ctor->SetClassName(Nan::New("Matrix").ToLocalChecked()); // Prototype + Nan::SetPrototypeMethod(ctor, "copyMakeBorder", CopyMakeBorder); Nan::SetPrototypeMethod(ctor, "row", Row); Nan::SetPrototypeMethod(ctor, "col", Col); Nan::SetPrototypeMethod(ctor, "pixelRow", PixelRow); @@ -2544,6 +2545,54 @@ NAN_METHOD(Matrix::Mean) { info.GetReturnValue().Set(arr); } +NAN_METHOD(Matrix::CopyMakeBorder) { + SETUP_FUNCTION(Matrix) + + double t = info[0]->NumberValue(); + double b = info[1]->NumberValue(); + double l = info[2]->NumberValue(); + double r = info[3]->NumberValue(); + + int fill = cv::BORDER_DEFAULT; + cv::Scalar color; + if (info.Length() > 4) { + fill = info[4]->IntegerValue(); + color = cv::Scalar(0, 0, 0, 0); + if (fill == cv::BORDER_CONSTANT && info[5]->IsArray()) { + Local objColor = info[5]->ToObject(); + + Local valB = objColor->Get(0); + Local valG = objColor->Get(1); + Local valR = objColor->Get(2); + Local valA = objColor->Get(3); + + color = cv::Scalar( + valB->IntegerValue(), + valG->IntegerValue(), + valR->IntegerValue(), + valA->IntegerValue() + ); + } + } + + // if (info[6]->IsArray()) { + // Local objColor = info[4]->ToObject(); + // color = setColor(objColor); + // + // cv::Scalar color = cv::Scalar(valB->IntegerValue(), valG->IntegerValue(), + // valR->IntegerValue()); + // } + + // + cv::Mat padded; + cv::copyMakeBorder(self->mat, padded, t, b, l, r, fill, color); + // + ~self->mat; + self->mat = padded; + + return; +} + NAN_METHOD(Matrix::Shift) { SETUP_FUNCTION(Matrix) diff --git a/src/Matrix.h b/src/Matrix.h index ffa8ca6..c539130 100755 --- a/src/Matrix.h +++ b/src/Matrix.h @@ -27,6 +27,7 @@ public: JSFUNC(Normalize) JSFUNC(Brightness) JSFUNC(Norm) + JSFUNC(CopyMakeBorder) JSFUNC(Row) JSFUNC(PixelRow)