OpenCV stitcher fails to stitch undistorted images

牧云@^-^@ 提交于 2019-12-11 00:33:41

问题


I am trying to stitch a panorama using mobile phone camera with an attachable 170 degree wide angle lens. The resulting photo is distorted (fisheye). I understand that to stitch these photos using Stitcher::stitch(InputArrayOfArrays images, OutputArray pano) they must be undistorted first.

First, I did the undistort(InputArray src, OutputArray dst, InputArray cameraMatrix, InputArray distCoeffs, InputArray newCameraMatrix=noArray() ) and save the results to jpg files. Then, I read the jpg images, stitched them to be a panorama image and this worked well.

Next, I joined the process into a single process. So I did not save the undistorted image, but keep them in cv::Mat and use it as the stitcher input. This one fails with error code ERR_NEED_MORE_IMGS.

My question is, why does it work if the stitcher input (ImgArray) comes from imread, but fails if the input comes directly from undistort output? How to make the second case work?

//Load photo source (distorted)
Mat imageDistorted, imageUndistorted;
vector<Mat> ImgArray;

for (int p=1; p<=6; p++){
    imageDistorted = imread( "/file1.jpg" ); //read file2, file3, ...
    if(imageDistorted.data){
        undistort(imageDistorted, imageUndistorted, camVariables, distCoeffs);

        ImgArray.push_back( imageUndistorted );

    }
}

//Apply Stitching algorithm
Mat panoImg;
Stitcher stitcher = Stitcher::createDefault();

Stitcher::Status status = stitcher.stitch(ImgArray, panoImg);

来源:https://stackoverflow.com/questions/39696321/opencv-stitcher-fails-to-stitch-undistorted-images

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!