cv2 orb 图像拼接_OpenCV图片拼接的两种方法

本文介绍了两种使用OpenCV进行图像拼接的方法,包括简单拼接和基于ORB特征的高级拼接。通过展示代码示例,阐述了如何利用OpenCV库中的函数将多张图片无缝融合。
摘要由CSDN通过智能技术生成

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

一、原图

1.jpg                                        2.jpg                                            3.jpg

二、拼接效果

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

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

三、源代码(一)

#include

#include

#include

#pragmacomment(lib,"opencv_core245.lib")

#pragmacomment(lib,"opencv_highgui245.lib")

intmain(){

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<

system("pause");

return -1;

}

imgs.push_back(img);

}

cout<

Mat pano;

Stitcher stitcher = Stitcher::createDefault(false);

Stitcher::Status status = stitcher.stitch(imgs, pano);

if (status != Stitcher::OK)

{

cout<

system("pause");

return -1;

}

imwrite(dstFile, pano);

namedWindow("Result");

imshow("Result",pano);

waitKey(0);

destroyWindow("Result");

system("pause");

return 0;

}

注:

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值