Added copyMakeBorder function

This commit is contained in:
Fotios Lindiakos 2016-10-06 15:12:33 -04:00
parent 4586b9bd40
commit 5a306658df
2 changed files with 50 additions and 0 deletions

View File

@ -20,6 +20,7 @@ void Matrix::Init(Local<Object> 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<Object> objColor = info[5]->ToObject();
Local<Value> valB = objColor->Get(0);
Local<Value> valG = objColor->Get(1);
Local<Value> valR = objColor->Get(2);
Local<Value> valA = objColor->Get(3);
color = cv::Scalar(
valB->IntegerValue(),
valG->IntegerValue(),
valR->IntegerValue(),
valA->IntegerValue()
);
}
}
// if (info[6]->IsArray()) {
// Local<Object> 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)

View File

@ -27,6 +27,7 @@ public:
JSFUNC(Normalize)
JSFUNC(Brightness)
JSFUNC(Norm)
JSFUNC(CopyMakeBorder)
JSFUNC(Row)
JSFUNC(PixelRow)