• OpenCV图片拼接的两种方法


    https://my.oschina.net/xiaot99/blog/226589

    一、原图

    全景? OpenCV图片拼接 - von.Ryan.Hack - fengyhack@netease全景? OpenCV图片拼接 - von.Ryan.Hack - fengyhack@netease全景? OpenCV图片拼接 - von.Ryan.Hack - fengyhack@netease

                        1.jpg                                        2.jpg                                            3.jpg

     二、拼接效果

    1、拼接效果之一:简单拼接,有重叠,看着不太舒服

    全景? OpenCV图片拼接 - von.Ryan.Hack - fengyhack@netease

     2、拼接效果之二:高级拼接,这下貌似好多了

    全景? OpenCV图片拼接 - von.Ryan.Hack - fengyhack@netease

     三、源代码(一)

    #include <cv.h>
    #include <highgui.h>
    #include <stdlib.h>
    #pragma comment(lib,"opencv_core245.lib")
    #pragma comment(lib,"opencv_highgui245.lib")
    int main(){    
        char* file[3]={"1.jpg","2.jpg","3.jpg"};//3张原始图片    
        IplImage* pImg[3];      
        int i;    
        
        for(i=0;i<3;++i)        
            pImg[i]=cvLoadImage(file[i]);
            
        int sw=pImg[0]->width;    
        int sh=pImg[0]->height;
        IplImage* dstImg = cvCreateImage(cvSize(sw*3,sh),pImg[0]->depth,pImg[0]->nChannels);  
          
        cvZero(dstImg);
        printf("Please wait...
    ");
        
        for(i=0;i<3;++i) {          
            cvSetImageROI(dstImg, cvRect(i*sw,0,sw,sh));         
            cvCopy(pImg[i], dstImg);          
            cvResetImageROI(dstImg);    
        }
        
        cvNamedWindow("dstImg");    
        cvShowImage("dstImg", dstImg);   
        cvSaveImage("result1.jpg",dstImg);//拼接图片之一    
        
        cvWaitKey(0);    
        
        for(i=0;i<3;++i)   
            cvReleaseImage(&pImg[i]);    
            
         cvReleaseImage(&dstImg);    
         cvDestroyWindow("dstImg");      
         system("pause");    
         return 0;
    }

    2、源代码(二)

    #include <iostream>
    #include <fstream>
    #include "opencv2/highgui/highgui.hpp
    "#include "opencv2/stitching/stitcher.hpp"
    using namespace std;
    using namespace cv;
    #pragma comment(lib,"opencv_core245.lib")
    #pragma comment(lib,"opencv_highgui245.lib")
    #pragma comment(lib,"opencv_stitching245.lib")
    int main(void)
    {     
        string srcFile[3]={"1.jpg","2.jpg","3.jpg"};     
        string dstFile="result.jpg";     
        vector<Mat> imgs;
        for(int i=0;i<3;++i)     
        {          
             Mat img=imread(srcFile[i]);          
             if (img.empty())          
             {              
                 cout<<"Can't read image '"<<srcFile[i]<<"'
    ";              
                 system("pause");              
                 return -1;           
             }         
             imgs.push_back(img);     
        }
        cout<<"Please wait..."<<endl;     
        Mat pano;     
        Stitcher stitcher = Stitcher::createDefault(false);     
        Stitcher::Status status = stitcher.stitch(imgs, pano);
        if (status != Stitcher::OK)     
        {          
            cout<<"Can't stitch images, error code=" <<int(status)<<endl;          
            system("pause");         
            return -1;     
        }
        imwrite(dstFile, pano);    
        namedWindow("Result");     
        imshow("Result",pano);  
           
        waitKey(0);    
         
        destroyWindow("Result");
        system("pause");     
        return 0;
    }

    注:

    1、原始图片(1,2,3)来源http://blog.csdn.net/yang_xian521/article/details/7589431,缩放至1/4

    2、代码(一)参考http://www.cnblogs.com/CBDoctor/archive/2011/09/19/2180998.html ,有较小改动

    3、代码(二)参考OpenCV自带samplescppstitching.cpp,改动较大

  • 相关阅读:
    训练集、验证集和测试集的区别
    视频分类论文“Towards Good Practices for Very Deep Two-Stream ConvNets”程序运行过程
    201571030304/201571030311《小学四则运算练习软件软件需求说明》结对项目报告
    201571030304/201571030311《小学四则运算练习软件》结对项目报告
    实验二 软件工程个人项目
    实验一 软件工程准备
    MySQL的卸载与安装
    大宗商品
    Web_Servlet四大域对象
    Web_Servlet之间请求转发
  • 原文地址:https://www.cnblogs.com/jukan/p/6297894.html
Copyright © 2020-2023  润新知