Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/Matrix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ Matrix::Init(Handle<Object> target) {
NODE_SET_PROTOTYPE_METHOD(constructor, "copyWithMask", CopyWithMask);
NODE_SET_PROTOTYPE_METHOD(constructor, "setWithMask", SetWithMask);
NODE_SET_PROTOTYPE_METHOD(constructor, "meanWithMask", MeanWithMask);
NODE_SET_PROTOTYPE_METHOD(constructor, "shift", Shift);


target->Set(String::NewSymbol("Matrix"), m->GetFunction());
Expand Down Expand Up @@ -1941,3 +1942,37 @@ Matrix::MeanWithMask(const v8::Arguments& args) {

return scope.Close(arr);
}

Handle<Value>
Matrix::Shift(const v8::Arguments& args){
SETUP_FUNCTION(Matrix)

cv::Mat res;

double tx = args[0]->NumberValue();
double ty = args[1]->NumberValue();

// get the integer values of args
cv::Point2i deltai(ceil(tx), ceil(ty));

int fill=cv::BORDER_REPLICATE;
cv::Scalar value=cv::Scalar(0,0,0,0);

// INTEGER SHIFT
// first create a border around the parts of the Mat that will be exposed
int t = 0, b = 0, l = 0, r = 0;
if (deltai.x > 0) l = deltai.x;
if (deltai.x < 0) r = -deltai.x;
if (deltai.y > 0) t = deltai.y;
if (deltai.y < 0) b = -deltai.y;
cv::Mat padded;
cv::copyMakeBorder(self->mat, padded, t, b, l, r, fill, value);

// construct the region of interest around the new matrix
cv::Rect roi = cv::Rect(std::max(-deltai.x,0),std::max(-deltai.y,0),0,0) + self->mat.size();
res = padded(roi);
~self->mat;
self->mat = res;

return scope.Close(Undefined());
}
1 change: 1 addition & 0 deletions src/Matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class Matrix: public node::ObjectWrap {
JSFUNC(CopyWithMask)
JSFUNC(SetWithMask)
JSFUNC(MeanWithMask)
JSFUNC(Shift)
/*
static Handle<Value> Val(const Arguments& args);
static Handle<Value> RowRange(const Arguments& args);
Expand Down