OpenCV图片拼接
2014-04-25 18:01
363 查看
一、原图
1.jpg 2.jpg 3.jpg
二、拼接效果
1、拼接效果之一:简单拼接,有重叠,看着不太舒服
2、拼接效果之二:高级拼接,这下貌似好多了
三、源代码(一)
2、源代码(二)
注:
1、原始图片(1,2,3)来源/article/1390603.html,缩放至1/4
2、代码(一)参考http://www.cnblogs.com/CBDoctor/archive/2011/09/19/2180998.html ,有较小改动
3、代码(二)参考OpenCV自带samples\cpp\stitching.cpp,改动较大
1.jpg 2.jpg 3.jpg
二、拼接效果
1、拼接效果之一:简单拼接,有重叠,看着不太舒服
2、拼接效果之二:高级拼接,这下貌似好多了
三、源代码(一)
#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...\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 <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]<<"'\n"; 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)来源/article/1390603.html,缩放至1/4
2、代码(一)参考http://www.cnblogs.com/CBDoctor/archive/2011/09/19/2180998.html ,有较小改动
3、代码(二)参考OpenCV自带samples\cpp\stitching.cpp,改动较大
相关文章推荐
- OpenCV图片拼接的两种方法
- opencv图片拼接报错cv::Stitcher::ERR_NEED_MORE_IMGS (1)
- OpenCV SIFT/SURF图片拼接融合
- 使用opencv把图片拼接成视频
- Opencv3.3 人脸识别 图片拼接 Android
- opencv来实现图片拼接
- OpenCV图片拼接
- 初学opencv心得:图片拼接Stitcher函数
- 使用OpenCVForUnity拼接图片
- OpenCV-008:抠图与图片拼接
- 关于全景(360)图片拼接的方法(Opencv3.0 Stitcher)
- opencv图片全景拼接详解
- OpenCV图片拼接
- opencv合并图片
- Java____随机数+时间戳+拼接=图片命名
- Qt creator5.7 OpenCV249之图片旋转(含源码下载)
- Qt creator5.7 OpenCV249之图片腐化(含源码下载)
- 《OpenCV》Part3 OpenCV3.1.0一幅图中同时显示三张图片(效果对比)
- 在QT集成开发环境中用OpenCV读取一张图片显示在Qlabel上
- OpenCV cv::mat 保存四通道图片 参数