[英]round robin image rotation what is the best way to do in opencv
I want to do a round robin image rotation as shown below. 我想进行循环图像旋转,如下所示。
The x vertical line from the start of image is removed and added to the end of image. 从图像起点开始的x垂直线被移除并添加到图像的末尾。
What is the best way to do this in OpenCV, GDI++ and WPF? 在OpenCV,GDI ++和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) 我需要在具有以下签名的函数中实现它(对于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 . 对于OpenCV,请看一下重映射 。
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 您也可以使用ROI
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 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.