I want to do a round robin image rotation as shown below. enter image description here

The x vertical line from the start of image is removed and added to the end of image.

What is the best way to do this in OpenCV, GDI++ and WPF? I need a solution for each of these platform but they could be implemented differently.

I need to implement it in a function with the following signature(for opencv)

  Mat CircShift(Mat inputImage, int PixelInXdirectionToShift);

I know how can I do this by manipulating pixels, but I am looking for a solution that do this very fast when pixel manipulation is not that fast.

有帮助吗?

解决方案

Mat outImg(inputImg.size(),inputImg.type());
inputImg(Rect(0, 0, shiftX, height)).copyTo(outImg(Rect(width-shiftX, 0, shiftX, height)));
inputImg(Rect(shiftX, 0, width-shiftX, height)).copyTo(outImg(Rect(0, 0, width-shiftX, height)));

其他提示

For OpenCV take a look at remap.

EDIT: Easy/Quick creation of map (using vector):

//Create vector of what the rows/cols look like
std::vector<int> t_X,t_Y;
for (int i = 0; i < img.cols(); i++) t_X.push_back(i);
for (int i = 0; i < img.rows(); i++) t_Y.push_back(i);

//circular shift t_X vector
std::vector<int>::iterator it;
int zeroPixel = 50; //This x-pixel to bring to 0 (shifting to the left)

it = std::find(t_X.begin(), t_X.end(), zeroPixel);
std::rotate(t_X.begin(), it, t_X.end());

//Create Maps
 //Turn vectors in cv::Mat
 cv::Mat xRange = cv::Mat(t_X);
 cv::Mat yRange = cv::Mat(t_Y);
 //Maps
 cv::Mat xMap;
 cv::Mat yMap;

 cv::repeat(xRange.reshape(1,1), yRange.total(), 1, xMap);
 cv::repeat(yRange.reshape(1,1).t(), 1, xRange.total(), yMap);

You could also use ROIs

int zeroPixel = 50;
cv::Mat newMat;
cv::Mat rightHalf = img(cv::Rect(0,0,zeroPixel,img.rows()));
cv::Mat leftHalf = img(cv::Rect(0,zeroPixel+1,img.cols()-zeroPixel-1,img.rows());
cv::hconcat(leftHalf , rightHalf , newMat);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top