diff --git a/examples/convert_image.js b/examples/convert_image.js index 0f130ae..db6d31a 100755 --- a/examples/convert_image.js +++ b/examples/convert_image.js @@ -6,6 +6,7 @@ cv.readImage("./mona.png", function(err, im) { img_hsv = im.copy(); img_gray = im.copy(); + img_hsv.convertHSVscale(); img_gray.convertGrayscale(); @@ -15,6 +16,9 @@ cv.readImage("./mona.png", function(err, im) { img_hsv.save("/tmp/hsv.png"); img_gray.save("/tmp/gray.png"); + img_crop = im.crop(50,50,250,250); + img_crop.save("crop.png"); + console.log("Guardado"); }); diff --git a/src/Matrix.cc b/src/Matrix.cc index 6dc9ea6..e1db521 100755 --- a/src/Matrix.cc +++ b/src/Matrix.cc @@ -55,6 +55,8 @@ Matrix::Init(Handle target) { NODE_SET_PROTOTYPE_METHOD(constructor, "pyrUp", PyrUp); NODE_SET_PROTOTYPE_METHOD(constructor, "channels", Channels); + NODE_SET_PROTOTYPE_METHOD(constructor, "crop", Crop); + NODE_SET_PROTOTYPE_METHOD(constructor, "convertGrayscale", ConvertGrayscale); NODE_SET_PROTOTYPE_METHOD(constructor, "convertHSVscale", ConvertHSVscale); NODE_SET_PROTOTYPE_METHOD(constructor, "gaussianBlur", GaussianBlur); @@ -318,6 +320,31 @@ Matrix::Clone(const Arguments& args){ return scope.Close(im_h); } +Handle +Matrix::Crop(const Arguments& args){ + + SETUP_FUNCTION(Matrix) + + if ((args.Length() == 4) && (args[0]->IsNumber()) && (args[1]->IsNumber()) && (args[2]->IsNumber()) && (args[3]->IsNumber())){ + + int x = args[0]->IntegerValue(); + int y = args[1]->IntegerValue(); + int width = args[2]->IntegerValue(); + int height = args[3]->IntegerValue(); + + cv::Rect roi(x, y, width, height); + + Local im_h = Matrix::constructor->GetFunction()->NewInstance(); + Matrix *m = ObjectWrap::Unwrap(im_h); + m->mat = self->mat(roi); + + return scope.Close(im_h); + } + else{ + return scope.Close(v8::String::New("Insufficient or wrong arguments")); + } +} + Handle Matrix::Row(const Arguments& args){ SETUP_FUNCTION(Matrix) diff --git a/src/Matrix.h b/src/Matrix.h index 3331e44..ec89884 100755 --- a/src/Matrix.h +++ b/src/Matrix.h @@ -73,6 +73,8 @@ class Matrix: public node::ObjectWrap { JSFUNC(GoodFeaturesToTrack) JSFUNC(HoughLinesP) + JSFUNC(Crop) + JSFUNC(inRange) JSFUNC(LocateROI)