Stitching 2 images (OpenCV)

非 Y 不嫁゛ 提交于 2019-12-01 23:43:54

It seems that you have a lot of outliers that make the estimation of homography is incorrect. SO you can use RANSAC method that recursively reject those outliers.

No need much efforts for that, just use a third parameter in findHomography function as:

Mat H = Calib3d.findHomography(obj, scene, CV_RANSAC);

Edit

Then try to be sure that your images given to detector are 8-bit grayscale image, as mentioned here

The "incorrectly stitched image" you post looks like having a bad conditioned H matrix. Apart from +dervish suggestions, run:

cv::determinant(H) > 0.01

To check if your H matrix is "usable". If the matrix is badly conditioned, you get the effect you are showing.

You are drawing onto a 2x2 canvas size, if that's the case, you won't see plenty of stitching configurations, i.e. it's ok for image A on the left of image B but not otherwise. Try drawing the output onto a 3x3 canvas size, using the following snippet:

  // Use the Homography Matrix to warp the images, but offset it to the
  // center of the output canvas. Careful to pre-multiply, not post-multiply.
  cv::Mat Offset = (cv::Mat_<double>(3,3) << 1, 0, 
                    width, 0, 1, height, 0, 0, 1);
  H = Offset * H;

  cv::Mat result;
  cv::warpPerspective(mat_l,
                      result,
                      H,
                      cv::Size(3*width, 3*height));
  // Copy the reference image to the center of the 3x3 output canvas.
  cv::Mat roi = result.colRange(width,2*width).rowRange(height,2*height);
  mat_r.copyTo(roi);

Where width and height are those of the input images, supposedly both of the same size. Note that this warping assumes the mat_l unchanged (flat) and mat_r warping to get stitched on it.

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