mirror of
https://github.com/peterbraden/node-opencv.git
synced 2025-12-08 19:45:55 +00:00
Merge pull request #46 from RNELord/master
Matrix::flip, Matrix::ROI, Matrix::rotate
This commit is contained in:
commit
aa7b3317fe
@ -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);
|
||||
@ -54,6 +55,8 @@ Matrix::Init(Handle<Object> target) {
|
||||
NODE_SET_PROTOTYPE_METHOD(constructor, "convertHSVscale", ConvertHSVscale);
|
||||
NODE_SET_PROTOTYPE_METHOD(constructor, "gaussianBlur", GaussianBlur);
|
||||
NODE_SET_PROTOTYPE_METHOD(constructor, "copy", Copy);
|
||||
NODE_SET_PROTOTYPE_METHOD(constructor, "flip", Flip);
|
||||
NODE_SET_PROTOTYPE_METHOD(constructor, "roi", ROI);
|
||||
NODE_SET_PROTOTYPE_METHOD(constructor, "ptr", Ptr);
|
||||
NODE_SET_PROTOTYPE_METHOD(constructor, "addWeighted", AddWeighted);
|
||||
NODE_SET_PROTOTYPE_METHOD(constructor, "split", Split);
|
||||
@ -694,6 +697,54 @@ Matrix::Copy(const v8::Arguments& args) {
|
||||
}
|
||||
|
||||
|
||||
Handle<Value>
|
||||
Matrix::Flip(const v8::Arguments& args) {
|
||||
HandleScope scope;
|
||||
|
||||
Matrix *self = ObjectWrap::Unwrap<Matrix>(args.This());
|
||||
|
||||
if ( args.Length() < 1 || !args[0]->IsInt32() ) {
|
||||
return v8::ThrowException(Exception::TypeError(String::New(
|
||||
"Flip requires an integer flipCode argument (0 = X axis, positive = Y axis, negative = both axis)")));
|
||||
}
|
||||
|
||||
int flipCode = args[0]->ToInt32()->Value();
|
||||
|
||||
Local<Object> img_to_return = Matrix::constructor->GetFunction()->NewInstance();
|
||||
Matrix *img = ObjectWrap::Unwrap<Matrix>(img_to_return);
|
||||
cv::flip(self->mat, img->mat, flipCode);
|
||||
|
||||
return scope.Close(img_to_return);
|
||||
}
|
||||
|
||||
|
||||
Handle<Value>
|
||||
Matrix::ROI(const v8::Arguments& args) {
|
||||
HandleScope scope;
|
||||
|
||||
Matrix *self = ObjectWrap::Unwrap<Matrix>(args.This());
|
||||
|
||||
if ( args.Length() != 4 ) {
|
||||
return v8::ThrowException(Exception::TypeError(String::New(
|
||||
"ROI requires x,y,w,h arguments")));
|
||||
}
|
||||
|
||||
// although it's an image to return, it is in fact a pointer to ROI of parent matrix
|
||||
Local<Object> img_to_return = Matrix::constructor->GetFunction()->NewInstance();
|
||||
Matrix *img = ObjectWrap::Unwrap<Matrix>(img_to_return);
|
||||
|
||||
int x = args[0]->IntegerValue();
|
||||
int y = args[1]->IntegerValue();
|
||||
int w = args[2]->IntegerValue();
|
||||
int h = args[3]->IntegerValue();
|
||||
|
||||
cv::Mat roi(self->mat, cv::Rect(x,y,w,h));
|
||||
img->mat = roi;
|
||||
|
||||
return scope.Close(img_to_return);
|
||||
}
|
||||
|
||||
|
||||
Handle<Value>
|
||||
Matrix::Ptr(const v8::Arguments& args) {
|
||||
HandleScope scope;
|
||||
@ -925,6 +976,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)
|
||||
|
||||
@ -42,6 +42,7 @@ class Matrix: public node::ObjectWrap {
|
||||
JSFUNC(ToBufferAsync)
|
||||
|
||||
JSFUNC(Resize)
|
||||
JSFUNC(Rotate)
|
||||
JSFUNC(PyrDown)
|
||||
JSFUNC(PyrUp)
|
||||
|
||||
@ -49,6 +50,8 @@ class Matrix: public node::ObjectWrap {
|
||||
JSFUNC(ConvertHSVscale)
|
||||
JSFUNC(GaussianBlur)
|
||||
JSFUNC(Copy)
|
||||
JSFUNC(Flip)
|
||||
JSFUNC(ROI)
|
||||
JSFUNC(Ptr)
|
||||
JSFUNC(AddWeighted)
|
||||
JSFUNC(Split)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user