@@ -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+ }
0 commit comments