I was looking for the same question, but since it is not there, I wrote it myself. Here is another option. In my code, you can shift right or left n times: for left numRight is -n, right +n .
void shiftCol(Mat& out, Mat in, int numRight){ if(numRight == 0){ in.copyTo(out); return; } int ncols = in.cols; int nrows = in.rows; out = Mat::zeros(in.size(), in.type()); numRight = numRight%ncols; if(numRight < 0) numRight = ncols+numRight; in(cv::Rect(ncols-numRight,0, numRight,nrows)).copyTo(out(cv::Rect(0,0,numRight,nrows))); in(cv::Rect(0,0, ncols-numRight,nrows)).copyTo(out(cv::Rect(numRight,0,ncols-numRight,nrows))); }
Hope this helps some people. Similarly, shiftRows can be written
source share