OpenCv1.0 实现2副图像的拼接

其实当然你可以实现任意图像的拼接,只要你将单个图片的位置在整体图片放在适当的位置(按照你自己的设置来),就可以实现图片的拼接了。

直接上code吧,注意是用的是opencv1.0,另外2副图像的通道数应该要一样。



#include<cv.h>

#include<highgui.h>
#include<cvaux.h>
#include<cxcore.h>


#include<iostream>
#include<fstream>
using namespace std;


#pragma comment(lib,"cv.lib");
#pragma comment(lib,"cvaux.lib");
#pragma comment(lib,"cxcore.lib");
#pragma comment(lib,"highgui.lib");




int main()
{
IplImage* src1 ;
IplImage* src2 ;
IplImage* des1;
IplImage* des2;
IplImage* des ;
src1 = cvLoadImage("image1.jpg",0);
src2 = cvLoadImage("image2.jpg",0);


des1 = cvCreateImage(cvSize(320,240),src1->depth, src1->nChannels);
cvResize(src1,des1,1);
des2 = cvCreateImage(cvSize(320,240),src2->depth, src2->nChannels);
cvResize(src2,des2,1); 
    //cvResize(src2,des2,CV_INTER_LINEAR);


des = cvCreateImage(cvSize(640,240),src1->depth, src1->nChannels);


    
// load the two images to the destinate position 
cvSetImageROI(des, cvRect(0, 0, 320, 240));
cvCopy(des1, des);
cvResetImageROI(des);
cvSetImageROI(des, cvRect(320, 0, 640, 240));
cvCopy(des2, des);
cvResetImageROI(des);


cvNamedWindow("result",3);
cvShowImage("result", des);
cvWaitKey(0);
cvReleaseImage(&src1);
cvReleaseImage(&src2);
cvReleaseImage(&des1);
cvReleaseImage(&des2);
cvReleaseImage(&des);
cvDestroyWindow("result");


return 0;
}

你可能感兴趣的:(OpenCv1.0 实现2副图像的拼接)