mirror of
https://github.com/peterbraden/node-opencv.git
synced 2025-12-08 19:45:55 +00:00
Merge pull request #334 from jainanshul/reshape
Add matrix reshape function
This commit is contained in:
commit
fdc2f6b49a
@ -105,6 +105,7 @@ void Matrix::Init(Local<Object> target) {
|
|||||||
Nan::SetPrototypeMethod(ctor, "setWithMask", SetWithMask);
|
Nan::SetPrototypeMethod(ctor, "setWithMask", SetWithMask);
|
||||||
Nan::SetPrototypeMethod(ctor, "meanWithMask", MeanWithMask);
|
Nan::SetPrototypeMethod(ctor, "meanWithMask", MeanWithMask);
|
||||||
Nan::SetPrototypeMethod(ctor, "shift", Shift);
|
Nan::SetPrototypeMethod(ctor, "shift", Shift);
|
||||||
|
Nan::SetPrototypeMethod(ctor, "reshape", Reshape);
|
||||||
Nan::SetPrototypeMethod(ctor, "release", Release);
|
Nan::SetPrototypeMethod(ctor, "release", Release);
|
||||||
|
|
||||||
target->Set(Nan::New("Matrix").ToLocalChecked(), ctor->GetFunction());
|
target->Set(Nan::New("Matrix").ToLocalChecked(), ctor->GetFunction());
|
||||||
@ -2415,6 +2416,32 @@ NAN_METHOD(Matrix::Shift) {
|
|||||||
return;
|
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_METHOD(Matrix::Release) {
|
||||||
Nan::HandleScope scope;
|
Nan::HandleScope scope;
|
||||||
|
|
||||||
|
|||||||
@ -120,6 +120,7 @@ public:
|
|||||||
JSFUNC(SetWithMask)
|
JSFUNC(SetWithMask)
|
||||||
JSFUNC(MeanWithMask)
|
JSFUNC(MeanWithMask)
|
||||||
JSFUNC(Shift)
|
JSFUNC(Shift)
|
||||||
|
JSFUNC(Reshape)
|
||||||
|
|
||||||
JSFUNC(Release)
|
JSFUNC(Release)
|
||||||
/*
|
/*
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user