From ee3ae4c1968b1acd54d389bac742c5c6d8e32ca3 Mon Sep 17 00:00:00 2001 From: Oskar Dahlberg Date: Mon, 22 Sep 2014 21:54:40 +0200 Subject: [PATCH] Added Zeros, Ones constructors --- src/Matrix.cc | 39 ++++++++++++++++++++++++++++++++++++--- src/Matrix.h | 2 ++ 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/Matrix.cc b/src/Matrix.cc index 3a3fce0..25cb14a 100755 --- a/src/Matrix.cc +++ b/src/Matrix.cc @@ -108,7 +108,9 @@ Matrix::Init(Handle target) { NODE_SET_PROTOTYPE_METHOD(constructor, "getPerspectiveTransform", GetPerspectiveTransform); NODE_SET_PROTOTYPE_METHOD(constructor, "warpPerspective", WarpPerspective); - NODE_SET_METHOD(constructor, "Eye", Eye); + NODE_SET_METHOD(constructor, "Zeros", Zeros); + NODE_SET_METHOD(constructor, "Ones", Ones); + NODE_SET_METHOD(constructor, "Eye", Eye); NODE_SET_PROTOTYPE_METHOD(constructor, "copyWithMask", CopyWithMask); NODE_SET_PROTOTYPE_METHOD(constructor, "setWithMask", SetWithMask); @@ -820,6 +822,37 @@ void AfterSaveAsync(uv_work_t *req) { delete baton; } +Handle +Matrix::Zeros(const v8::Arguments& args){ + HandleScope scope; + + int w = args[0]->Uint32Value(); + int h = args[1]->Uint32Value(); + int type = (args.Length() > 2) ? args[2]->IntegerValue() : CV_64FC1; + + Local im_h = Matrix::constructor->GetFunction()->NewInstance(); + Matrix *img = ObjectWrap::Unwrap(im_h); + cv::Mat mat = cv::Mat::zeros(w, h, type); + + img->mat = mat; + return scope.Close(im_h); +} + +Handle +Matrix::Ones(const v8::Arguments& args){ + HandleScope scope; + + int w = args[0]->Uint32Value(); + int h = args[1]->Uint32Value(); + int type = (args.Length() > 2) ? args[2]->IntegerValue() : CV_64FC1; + + Local im_h = Matrix::constructor->GetFunction()->NewInstance(); + Matrix *img = ObjectWrap::Unwrap(im_h); + cv::Mat mat = cv::Mat::ones(w, h, type); + + img->mat = mat; + return scope.Close(im_h); +} Handle Matrix::Eye(const v8::Arguments& args){ @@ -827,16 +860,16 @@ Matrix::Eye(const v8::Arguments& args){ int w = args[0]->Uint32Value(); int h = args[1]->Uint32Value(); + int type = (args.Length() > 2) ? args[2]->IntegerValue() : CV_64FC1; Local im_h = Matrix::constructor->GetFunction()->NewInstance(); Matrix *img = ObjectWrap::Unwrap(im_h); - cv::Mat mat = cv::Mat::eye(w, h, CV_64FC1); + cv::Mat mat = cv::Mat::eye(w, h, type); img->mat = mat; return scope.Close(im_h); } - Handle Matrix::ConvertGrayscale(const v8::Arguments& args) { HandleScope scope; diff --git a/src/Matrix.h b/src/Matrix.h index ec89884..2cdb329 100755 --- a/src/Matrix.h +++ b/src/Matrix.h @@ -14,6 +14,8 @@ class Matrix: public node::ObjectWrap { static double DblGet(cv::Mat mat, int i, int j); + JSFUNC(Zeros) // factory + JSFUNC(Ones) // factory JSFUNC(Eye) // factory JSFUNC(Get) // at