round robin image rotation what is the best way to do in opencv

后端 未结 2 834
余生分开走
余生分开走 2020-12-21 23:53

I want to do a round robin image rotation as shown below. \"enter

The x vertical line

相关标签:
2条回答
  • 2020-12-22 00:11

    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);
    
    0 讨论(0)
  • 2020-12-22 00:29
    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)));
    
    0 讨论(0)
提交回复
热议问题