From 3105e14f25d67857d0c2ececc33eaf74a6dc9479 Mon Sep 17 00:00:00 2001 From: Paul Date: Thu, 22 Aug 2013 05:06:58 +0400 Subject: [PATCH] implemented copyTo() func --- src/Matrix.cc | 32 ++++++++++++++++++++++++++++++++ src/Matrix.h | 3 +++ 2 files changed, 35 insertions(+) diff --git a/src/Matrix.cc b/src/Matrix.cc index 8cbc363..6363408 100755 --- a/src/Matrix.cc +++ b/src/Matrix.cc @@ -47,6 +47,7 @@ Matrix::Init(Handle target) { 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, "copyTo", CopyTo); NODE_SET_PROTOTYPE_METHOD(constructor, "pyrDown", PyrDown); NODE_SET_PROTOTYPE_METHOD(constructor, "pyrUp", PyrUp); NODE_SET_PROTOTYPE_METHOD(constructor, "channels", Channels); @@ -1175,3 +1176,34 @@ Matrix::MeanStdDev(const v8::Arguments& args) { data->Set(String::NewSymbol("stddev"), stddev); return scope.Close(data); } + + +// @author SergeMv +// Copies our (small) image into a ROI of another (big) image +// @param Object another image (destination) +// @param Number Destination x (where our image is to be copied) +// @param Number Destination y (where our image is to be copied) +// Example: smallImg.copyTo(bigImg, 50, 50); +// Note, x,y and width and height of our image must be so that +// our.width + x <= destination.width (and the same for y and height) +// both x and y must be >= 0 +Handle +Matrix::CopyTo(const v8::Arguments& args){ + HandleScope scope; + + Matrix * self = ObjectWrap::Unwrap(args.This()); + int width = self->mat.size().width; + int height = self->mat.size().height; + + // param 0 - destination image: + Matrix *dest = ObjectWrap::Unwrap(args[0]->ToObject()); + // param 1 - x coord of the destination + int x = args[1]->IntegerValue(); + // param 2 - y coord of the destination + int y = args[2]->IntegerValue(); + + cv::Mat dstROI = cv::Mat(dest->mat, cv::Rect(x, y, width, height)); + self->mat.copyTo(dstROI); + + return scope.Close(Undefined()); +} \ No newline at end of file diff --git a/src/Matrix.h b/src/Matrix.h index 3dcb691..d6dceba 100755 --- a/src/Matrix.h +++ b/src/Matrix.h @@ -77,6 +77,9 @@ class Matrix: public node::ObjectWrap { JSFUNC(Threshold) JSFUNC(MeanStdDev) + + JSFUNC(CopyTo) + /* static Handle Val(const Arguments& args); static Handle RowRange(const Arguments& args);