4 thoughts on “Sample results from Simple Pano Stitcher”

  1. Hi, I am a newer to OpenCV.
    I have get the picture of layer-000.png ~ layer-005.png
    But I don’t know how to merge it;
    I use the code:
    addWeighted( resutlsMat.at(0), 0.2, resutlsMat.at(1), 0.8, 0.0, results);
    addWeighted( results, 0.5, resutlsMat.at(2), 0.5, 0.0, results);
    addWeighted( results, 0.5, resutlsMat.at(3), 0.5, 0.0, results);
    addWeighted( results, 0.5, resutlsMat.at(4), 0.5, 0.0, results);
    but it failed.
    could you give me a example how to merge the 5 pictures together.

    best regards.

    1. Here’s one way

          Mat imgs[3];
          imgs[0] = imread("layer-000.png", -1); // -1 = load image 'as is', no conversion
          imgs[1] = imread("layer-001.png", -1);
          imgs[2] = imread("layer-002.png", -1);
          assert(imgs[0].channels() == 4);
          Mat out = Mat::zeros(imgs[0].size(), CV_32SC3);
          Mat count = Mat::zeros(imgs[0].size(), CV_32S);
          // Sum
          for(int i=0; i < 3; i++) {
              for(int y=0; y < out.rows; y++) {
                  for(int x=0; x < out.cols; x++) {
                      if(imgs[i].at<cv::Vec4b>(y,x)[3] > 0) { // check alpha
                          out.at<cv::Vec3i>(y,x)[0] += imgs[i].at<cv::Vec4b>(y,x)[0];
                          out.at<cv::Vec3i>(y,x)[1] += imgs[i].at<cv::Vec4b>(y,x)[1];
                          out.at<cv::Vec3i>(y,x)[2] += imgs[i].at<cv::Vec4b>(y,x)[2];
          // Average
          for(int y=0; y < out.rows; y++) {
              for(int x=0; x < out.cols; x++) {
                  if(count.at<int>(y,x) == 0)
                  out.at<cv::Vec3i>(y,x)[0] /= count.at<int>(y,x);
                  out.at<cv::Vec3i>(y,x)[1] /= count.at<int>(y,x);
                  out.at<cv::Vec3i>(y,x)[2] /= count.at<int>(y,x);
          imwrite("combined.png", out);
  2. Hi nghiaho12,
    I see that your stitching is not perfect in some points of the final image. Some lines are not matched correctly (e.g. sidewalk), is it correct, or is it only an optical effect?
    I’m trying to use your images set with my software to stitch. I wrote some posts in OpenCV forum (http://answers.opencv.org/question/59586/dense-optical-flow-for-stitching/) and EmguCV (http://www.emgu.com/forum/viewtopic.php?f=2&t=5144)

    I’m trying to use some dense algorithms (optical flow) but I can’t obtain good result while with feature-methods all work!
    Did you ever try to stitch with dense methods? Thanks

    1. Hi,

      The imperfection is normal, it’s hard to get perfect results due to unknown lens distortion. I haven’t tried dense optical flow. The stiching is very sensitive to the quality of the matching, which dense optical flow is unlikely to give compared to feature methods.

Leave a Reply

Your email address will not be published. Required fields are marked *