Merge pull request #174 from oskardahlberg/synced

Added Zeros, Ones constructors
This commit is contained in:
Peter Braden 2014-09-24 20:03:47 +02:00
commit e6f9ee971f
2 changed files with 38 additions and 3 deletions

View File

@ -108,6 +108,8 @@ Matrix::Init(Handle<Object> target) {
NODE_SET_PROTOTYPE_METHOD(constructor, "getPerspectiveTransform", GetPerspectiveTransform); NODE_SET_PROTOTYPE_METHOD(constructor, "getPerspectiveTransform", GetPerspectiveTransform);
NODE_SET_PROTOTYPE_METHOD(constructor, "warpPerspective", WarpPerspective); NODE_SET_PROTOTYPE_METHOD(constructor, "warpPerspective", WarpPerspective);
NODE_SET_METHOD(constructor, "Zeros", Zeros);
NODE_SET_METHOD(constructor, "Ones", Ones);
NODE_SET_METHOD(constructor, "Eye", Eye); NODE_SET_METHOD(constructor, "Eye", Eye);
NODE_SET_PROTOTYPE_METHOD(constructor, "copyWithMask", CopyWithMask); NODE_SET_PROTOTYPE_METHOD(constructor, "copyWithMask", CopyWithMask);
@ -826,6 +828,37 @@ void AfterSaveAsync(uv_work_t *req) {
delete baton; delete baton;
} }
Handle<Value>
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<Object> im_h = Matrix::constructor->GetFunction()->NewInstance();
Matrix *img = ObjectWrap::Unwrap<Matrix>(im_h);
cv::Mat mat = cv::Mat::zeros(w, h, type);
img->mat = mat;
return scope.Close(im_h);
}
Handle<Value>
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<Object> im_h = Matrix::constructor->GetFunction()->NewInstance();
Matrix *img = ObjectWrap::Unwrap<Matrix>(im_h);
cv::Mat mat = cv::Mat::ones(w, h, type);
img->mat = mat;
return scope.Close(im_h);
}
Handle<Value> Handle<Value>
Matrix::Eye(const v8::Arguments& args){ Matrix::Eye(const v8::Arguments& args){
@ -833,16 +866,16 @@ Matrix::Eye(const v8::Arguments& args){
int w = args[0]->Uint32Value(); int w = args[0]->Uint32Value();
int h = args[1]->Uint32Value(); int h = args[1]->Uint32Value();
int type = (args.Length() > 2) ? args[2]->IntegerValue() : CV_64FC1;
Local<Object> im_h = Matrix::constructor->GetFunction()->NewInstance(); Local<Object> im_h = Matrix::constructor->GetFunction()->NewInstance();
Matrix *img = ObjectWrap::Unwrap<Matrix>(im_h); Matrix *img = ObjectWrap::Unwrap<Matrix>(im_h);
cv::Mat mat = cv::Mat::eye(w, h, CV_64FC1); cv::Mat mat = cv::Mat::eye(w, h, type);
img->mat = mat; img->mat = mat;
return scope.Close(im_h); return scope.Close(im_h);
} }
Handle<Value> Handle<Value>
Matrix::ConvertGrayscale(const v8::Arguments& args) { Matrix::ConvertGrayscale(const v8::Arguments& args) {
HandleScope scope; HandleScope scope;

View File

@ -14,6 +14,8 @@ class Matrix: public node::ObjectWrap {
static double DblGet(cv::Mat mat, int i, int j); static double DblGet(cv::Mat mat, int i, int j);
JSFUNC(Zeros) // factory
JSFUNC(Ones) // factory
JSFUNC(Eye) // factory JSFUNC(Eye) // factory
JSFUNC(Get) // at JSFUNC(Get) // at