Matrix::rotate bind using cv::warpAffine

This commit is contained in:
Ryan Lord 2013-05-01 14:12:30 +01:00
parent c3d1379cd5
commit 7b3835bbf5
2 changed files with 26 additions and 0 deletions

View File

@ -46,6 +46,7 @@ Matrix::Init(Handle<Object> target) {
NODE_SET_PROTOTYPE_METHOD(constructor, "save", Save);
NODE_SET_PROTOTYPE_METHOD(constructor, "saveAsync", SaveAsync);
NODE_SET_PROTOTYPE_METHOD(constructor, "resize", Resize);
NODE_SET_PROTOTYPE_METHOD(constructor, "rotate", Rotate);
NODE_SET_PROTOTYPE_METHOD(constructor, "pyrDown", PyrDown);
NODE_SET_PROTOTYPE_METHOD(constructor, "pyrUp", PyrUp);
NODE_SET_PROTOTYPE_METHOD(constructor, "channels", Channels);
@ -973,6 +974,30 @@ Matrix::Resize(const v8::Arguments& args){
return scope.Close(Undefined());
}
Handle<Value>
Matrix::Rotate(const v8::Arguments& args){
HandleScope scope;
Matrix *self = ObjectWrap::Unwrap<Matrix>(args.This());
cv::Mat rotMatrix(2, 3, CV_32FC1);
cv::Mat res;
float angle = args[0]->ToNumber()->Value();
int x = args[1]->IsUndefined() ? round(self->mat.size().width / 2) : args[1]->Uint32Value();
int y = args[1]->IsUndefined() ? round(self->mat.size().height / 2) : args[2]->Uint32Value();
cv::Point center = cv::Point(x,y);
rotMatrix = getRotationMatrix2D(center, angle, 1.0);
cv::warpAffine(self->mat, res, rotMatrix, self->mat.size());
~self->mat;
self->mat = res;
return scope.Close(Undefined());
}
Handle<Value>
Matrix::PyrDown(const v8::Arguments& args){
SETUP_FUNCTION(Matrix)

View File

@ -42,6 +42,7 @@ class Matrix: public node::ObjectWrap {
JSFUNC(ToBufferAsync)
JSFUNC(Resize)
JSFUNC(Rotate)
JSFUNC(PyrDown)
JSFUNC(PyrUp)