diff --git a/src/Matrix.cc b/src/Matrix.cc index fc885a9..7460cd0 100644 --- a/src/Matrix.cc +++ b/src/Matrix.cc @@ -24,6 +24,8 @@ Matrix::Init(Handle target) { NODE_SET_PROTOTYPE_METHOD(constructor, "row", Row); NODE_SET_PROTOTYPE_METHOD(constructor, "col", Col); + NODE_SET_PROTOTYPE_METHOD(constructor, "pixelRow", PixelRow); + NODE_SET_PROTOTYPE_METHOD(constructor, "pixelCol", PixelCol); NODE_SET_PROTOTYPE_METHOD(constructor, "empty", Empty); NODE_SET_PROTOTYPE_METHOD(constructor, "get", Get); @@ -66,7 +68,7 @@ Matrix::Matrix(): ObjectWrap() { } Matrix::Matrix(int w, int h): ObjectWrap() { - mat = cv::Mat(w, h, CV_32FC1); + mat = cv::Mat(w, h, CV_32FC3); } Handle @@ -116,6 +118,33 @@ Handle Matrix::Row(const Arguments& args){ SETUP_FUNCTION(Matrix) + int width = self->mat.size().width; + int y = args[0]->IntegerValue(); + v8::Local arr = v8::Array::New(width); + + for (int x=0; xmat.channels() == 1){ + v = self->mat.at(y, x); + } else { + // Assume 3 channel RGB + unsigned int val = 0; + cv::Vec3b pixel = self->mat.at(y, x); + val &= (uchar) pixel.val[2]; + val &= ((uchar) pixel.val[1]) << 8; + val &= ((uchar) pixel.val[0]) << 16; + v = (double) val; + } + arr->Set(x, Number::New(v)); + } + return scope.Close(arr); +} + + +Handle +Matrix::PixelRow(const Arguments& args){ + SETUP_FUNCTION(Matrix) + int width = self->mat.size().width; int y = args[0]->IntegerValue(); v8::Local arr = v8::Array::New(width * 3); @@ -134,6 +163,33 @@ Handle Matrix::Col(const Arguments& args){ SETUP_FUNCTION(Matrix) + int height = self->mat.size().height; + int x = args[0]->IntegerValue(); + v8::Local arr = v8::Array::New(height); + + for (int y=0; ymat.channels() == 1){ + v = self->mat.at(y, x); + } else { + // Assume 3 channel RGB + unsigned int val = 0; + cv::Vec3b pixel = self->mat.at(y, x); + val &= (uchar) pixel.val[2]; + val &= ((uchar) pixel.val[1]) << 8; + val &= ((uchar) pixel.val[0]) << 16; + v = (double) val; + } + arr->Set(y, Number::New(v)); + } + return scope.Close(arr); +} + + +Handle +Matrix::PixelCol(const Arguments& args){ + SETUP_FUNCTION(Matrix) + int height = self->mat.size().height; int x = args[0]->IntegerValue(); v8::Local arr = v8::Array::New(height * 3); @@ -225,7 +281,7 @@ Matrix::Eye(const v8::Arguments& args){ Local im_h = Matrix::constructor->GetFunction()->NewInstance(); Matrix *img = ObjectWrap::Unwrap(im_h); - cv::Mat mat = cv::Mat::eye(w, h, CV_32FC1); + cv::Mat mat = cv::Mat::eye(w, h, CV_32F); img->mat = mat; return scope.Close(im_h); @@ -241,7 +297,7 @@ Matrix::Resize(const v8::Arguments& args){ int y = args[1]->Uint32Value(); Matrix *self = ObjectWrap::Unwrap(args.This()); - cv::Mat res = cv::Mat(x, y, CV_32FC1); + cv::Mat res = cv::Mat(x, y, CV_32FC3); cv::resize(self->mat, res, cv::Size(x, y), 0, 0, cv::INTER_LINEAR); ~self->mat; self->mat = res; diff --git a/src/Matrix.h b/src/Matrix.h index 389246e..959f209 100644 --- a/src/Matrix.h +++ b/src/Matrix.h @@ -13,7 +13,9 @@ class Matrix: public node::ObjectWrap { JSFUNC(Row) + JSFUNC(PixelRow) JSFUNC(Col) + JSFUNC(PixelCol) JSFUNC(Eye) // factory /* diff --git a/test/smoke.js b/test/smoke.js index cb8bd7e..b759371 100644 --- a/test/smoke.js +++ b/test/smoke.js @@ -202,6 +202,7 @@ vows.describe('Smoke Tests OpenCV').addBatch({ , "finds face": function(err, faces){ assert.isNull(err); assert.isArray(faces); + console.log(faces); assert.equal(faces.length, 1) }