mirror of
https://github.com/peterbraden/node-opencv.git
synced 2025-12-08 19:45:55 +00:00
add shift image entry
Shifts an image by an integer number of pixels x or y directions, with a BORDER_REPLICATE fill. uses the underlying copymakeborder opencv call
This commit is contained in:
parent
86560fd68b
commit
d9bfdee231
@ -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());
|
||||
@ -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());
|
||||
}
|
||||
@ -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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user