Skip to content

Commit 05e42b7

Browse files
committed
Merge pull request peterbraden#145 from jhludwig/shift-image
add shift image entry
2 parents 86560fd + d9bfdee commit 05e42b7

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/Matrix.cc

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ Matrix::Init(Handle<Object> target) {
111111
NODE_SET_PROTOTYPE_METHOD(constructor, "copyWithMask", CopyWithMask);
112112
NODE_SET_PROTOTYPE_METHOD(constructor, "setWithMask", SetWithMask);
113113
NODE_SET_PROTOTYPE_METHOD(constructor, "meanWithMask", MeanWithMask);
114+
NODE_SET_PROTOTYPE_METHOD(constructor, "shift", Shift);
114115

115116

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

19421943
return scope.Close(arr);
19431944
}
1945+
1946+
Handle<Value>
1947+
Matrix::Shift(const v8::Arguments& args){
1948+
SETUP_FUNCTION(Matrix)
1949+
1950+
cv::Mat res;
1951+
1952+
double tx = args[0]->NumberValue();
1953+
double ty = args[1]->NumberValue();
1954+
1955+
// get the integer values of args
1956+
cv::Point2i deltai(ceil(tx), ceil(ty));
1957+
1958+
int fill=cv::BORDER_REPLICATE;
1959+
cv::Scalar value=cv::Scalar(0,0,0,0);
1960+
1961+
// INTEGER SHIFT
1962+
// first create a border around the parts of the Mat that will be exposed
1963+
int t = 0, b = 0, l = 0, r = 0;
1964+
if (deltai.x > 0) l = deltai.x;
1965+
if (deltai.x < 0) r = -deltai.x;
1966+
if (deltai.y > 0) t = deltai.y;
1967+
if (deltai.y < 0) b = -deltai.y;
1968+
cv::Mat padded;
1969+
cv::copyMakeBorder(self->mat, padded, t, b, l, r, fill, value);
1970+
1971+
// construct the region of interest around the new matrix
1972+
cv::Rect roi = cv::Rect(std::max(-deltai.x,0),std::max(-deltai.y,0),0,0) + self->mat.size();
1973+
res = padded(roi);
1974+
~self->mat;
1975+
self->mat = res;
1976+
1977+
return scope.Close(Undefined());
1978+
}

src/Matrix.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ class Matrix: public node::ObjectWrap {
102102
JSFUNC(CopyWithMask)
103103
JSFUNC(SetWithMask)
104104
JSFUNC(MeanWithMask)
105+
JSFUNC(Shift)
105106
/*
106107
static Handle<Value> Val(const Arguments& args);
107108
static Handle<Value> RowRange(const Arguments& args);

0 commit comments

Comments
 (0)