How to merge two images in opencv?

前端 未结 4 1438
时光取名叫无心
时光取名叫无心 2020-12-08 07:41

I have calculated homography ,taken out perspective transform .I am able two display two images in one window but unable to merge them.Here are my example images->

4条回答
  •  执笔经年
    2020-12-08 08:43

    OpenCV already has image stitching implemented. If you compile with "-D BUILD_EXAMPLES", you can use the binary stitching_detailed. The usage is simple: ./stitching_detailed img1 img2 ...

    Or, you can just use the stitcher class (example from here):

    #include "opencv2/highgui/highgui.hpp"
    #include "opencv2/stitching/stitcher.hpp"
    
    using namespace std;
    using namespace cv;
    
    bool try_use_gpu = false;
    string result_name = "result.jpg";
    
    int main(int argc, char* argv[])
    {
        vector imgs;
        // add images...
    
        Mat pano;
        Stitcher stitcher = Stitcher::createDefault(try_use_gpu);
        stitcher.stitch(imgs, pano);
        imwrite(result_name, pano);
    }
    

提交回复
热议问题