Merge pull request #334 from jainanshul/reshape

Add matrix reshape function
This commit is contained in:
Peter Braden 2015-11-20 10:32:37 +01:00
commit fdc2f6b49a
2 changed files with 28 additions and 0 deletions

View File

@ -105,6 +105,7 @@ void Matrix::Init(Local<Object> 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;

View File

@ -120,6 +120,7 @@ public:
JSFUNC(SetWithMask)
JSFUNC(MeanWithMask)
JSFUNC(Shift)
JSFUNC(Reshape)
JSFUNC(Release)
/*