diff --git a/src/Matrix.cc b/src/Matrix.cc index 10bc2c2..97e890d 100755 --- a/src/Matrix.cc +++ b/src/Matrix.cc @@ -105,6 +105,7 @@ void Matrix::Init(Local target) { Nan::SetPrototypeMethod(ctor, "setWithMask", SetWithMask); Nan::SetPrototypeMethod(ctor, "meanWithMask", MeanWithMask); Nan::SetPrototypeMethod(ctor, "shift", Shift); + Nan::SetPrototypeMethod(ctor, "reshape", Reshape); Nan::SetPrototypeMethod(ctor, "release", Release); target->Set(Nan::New("Matrix").ToLocalChecked(), ctor->GetFunction()); @@ -2415,6 +2416,32 @@ NAN_METHOD(Matrix::Shift) { return; } +/** + * Changes the shape and/or the number of channels of a 2D matrix without + * copying the data. + * Reference:http://docs.opencv.org/2.4/modules/core/doc/basic_structures.html#mat-reshape + */ +NAN_METHOD(Matrix::Reshape) { + SETUP_FUNCTION(Matrix) + + int cn = 0; + int rows = 0; + if (info.Length() == 2) { + INT_FROM_ARGS(cn, 0); + INT_FROM_ARGS(rows, 1); + } else if (info.Length() == 1) { + INT_FROM_ARGS(cn, 0); + } else { + JSTHROW("Invalid number of arguments"); + } + + cv::Mat res = self->mat.reshape(cn, rows); + ~self->mat; + self->mat = res; + + return; +} + NAN_METHOD(Matrix::Release) { Nan::HandleScope scope; diff --git a/src/Matrix.h b/src/Matrix.h index dc92a4c..b26046f 100755 --- a/src/Matrix.h +++ b/src/Matrix.h @@ -120,6 +120,7 @@ public: JSFUNC(SetWithMask) JSFUNC(MeanWithMask) JSFUNC(Shift) + JSFUNC(Reshape) JSFUNC(Release) /*