diff --git a/src/Matrix.cc b/src/Matrix.cc index 5431b8f..fdccaf7 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); @@ -2989,6 +2990,61 @@ NAN_METHOD(Matrix::Mean) { info.GetReturnValue().Set(arr); } +// http://docs.opencv.org/2.4/modules/imgproc/doc/filtering.html#copymakeborder +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 borderType = cv::BORDER_DEFAULT; + cv::Scalar value; + if (info.Length() > 4) { + borderType = info[4]->IntegerValue(); + value = cv::Scalar(0, 0, 0, 0); + if (borderType == cv::BORDER_CONSTANT) { + if (!info[5]->IsArray()) { + Nan::ThrowTypeError("The argument must be an array"); + } + v8::Local objColor = v8::Local::Cast(info[5]); + unsigned int length = objColor->Length(); + + Local valB = objColor->Get(0); + Local valG = objColor->Get(1); + Local valR = objColor->Get(2); + + if (length == 3) { + value = cv::Scalar( + valB->IntegerValue(), + valG->IntegerValue(), + valR->IntegerValue() + ); + } else if (length == 4) { + Local valA = objColor->Get(3); + + value = cv::Scalar( + valB->IntegerValue(), + valG->IntegerValue(), + valR->IntegerValue(), + valA->IntegerValue() + ); + } else { + Nan::ThrowError("Fill must include 3 or 4 colors"); + } + } + } + + cv::Mat padded; + cv::copyMakeBorder(self->mat, padded, t, b, l, r, borderType, value); + + ~self->mat; + self->mat = padded; + + return; +} + NAN_METHOD(Matrix::Shift) { SETUP_FUNCTION(Matrix) diff --git a/src/Matrix.h b/src/Matrix.h index 61f62a3..03b3c57 100755 --- a/src/Matrix.h +++ b/src/Matrix.h @@ -34,6 +34,7 @@ public: JSFUNC(Normalize) JSFUNC(Brightness) JSFUNC(Norm) + JSFUNC(CopyMakeBorder) JSFUNC(Row) JSFUNC(PixelRow)