diff --git a/src/Matrix.cc b/src/Matrix.cc index 46be855..51a443b 100755 --- a/src/Matrix.cc +++ b/src/Matrix.cc @@ -47,6 +47,8 @@ void Matrix::Init(Local target) { Nan::SetPrototypeMethod(ctor, "saveAsync", SaveAsync); Nan::SetPrototypeMethod(ctor, "resize", Resize); Nan::SetPrototypeMethod(ctor, "rotate", Rotate); + Nan::SetPrototypeMethod(ctor, "getRotationMatrix2D", GetRotationMatrix2D); + Nan::SetPrototypeMethod(ctor, "warpAffine", WarpAffine); Nan::SetPrototypeMethod(ctor, "copyTo", CopyTo); Nan::SetPrototypeMethod(ctor, "pyrDown", PyrDown); Nan::SetPrototypeMethod(ctor, "pyrUp", PyrUp); @@ -1557,6 +1559,48 @@ NAN_METHOD(Matrix::Rotate) { return; } +NAN_METHOD(Matrix::GetRotationMatrix2D) { + Nan::HandleScope scope; + + Matrix *self = Nan::ObjectWrap::Unwrap(info.This()); + cv::Mat res; + + float angle = info[0]->ToNumber()->Value(); + int x = info[1]->IsUndefined() ? round(self->mat.size().width / 2) : + info[1]->Uint32Value(); + int y = info[2]->IsUndefined() ? round(self->mat.size().height / 2) : + info[2]->Uint32Value(); + double scale = info[3]->IsUndefined() ? 1.0 : info[3]->NumberValue(); + + cv::Point center = cv::Point(x,y); + res = getRotationMatrix2D(center, angle, scale); + + ~self->mat; + self->mat = res; + + return; +} + +NAN_METHOD(Matrix::WarpAffine) { + Nan::HandleScope scope; + + Matrix *self = Nan::ObjectWrap::Unwrap(info.This()); + cv::Mat res; + + Matrix *rotMatrix = Nan::ObjectWrap::Unwrap(info[0]->ToObject()); + + // Resize the image if size is specified + int dstRows = info[1]->IsUndefined() ? self->mat.rows : info[1]->Uint32Value(); + int dstCols = info[2]->IsUndefined() ? self->mat.cols : info[2]->Uint32Value(); + cv::Size resSize = cv::Size(dstRows, dstCols); + + cv::warpAffine(self->mat, res, rotMatrix->mat, resSize); + ~self->mat; + self->mat = res; + + return; +} + NAN_METHOD(Matrix::PyrDown) { SETUP_FUNCTION(Matrix) diff --git a/src/Matrix.h b/src/Matrix.h index 826b12e..c5857c6 100755 --- a/src/Matrix.h +++ b/src/Matrix.h @@ -51,6 +51,8 @@ public: JSFUNC(Resize) JSFUNC(Rotate) + JSFUNC(GetRotationMatrix2D) + JSFUNC(WarpAffine) JSFUNC(PyrDown) JSFUNC(PyrUp)