https://my.oschina.net/xiaot99/blog/226589
一、原图
1.jpg 2.jpg 3.jpg
二、拼接效果
1、拼接效果之一:简单拼接,有重叠,看着不太舒服
2、拼接效果之二:高级拼接,这下貌似好多了
三、源代码(一)
#include#include #include #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...\n"); 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#include #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 imgs; for(int i=0;i<3;++i) { Mat img=imread(srcFile[i]); if (img.empty()) { cout<<"Can't read image '"< <<"'\n"; system("pause"); return -1; } imgs.push_back(img); } cout<<"Please wait..."<
注:
1、原始图片(1,2,3)来源,缩放至1/4
2、代码(一)参考 ,有较小改动
3、代码(二)参考OpenCV自带samples\cpp\stitching.cpp,改动较大