OpenCV图片拼接的两种方法
https://my.oschina.net/xiaot99/blog/226589
一、原图
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)来源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自带samples\cpp\stitching.cpp,改动较大
OpenCV图片拼接的两种方法的更多相关文章
- 在linux环境下编译运行OpenCV程序的两种方法
原来以为在Ubuntu下安装好了OpenCV之后,自己写个简单的程序应该很容易吧,但是呢,就是为了编译一个简单的显示图片的程序我都快被弄崩溃了. 在谷歌和上StackOverFlow查看相关问题解答之 ...
- python+opencv图像变换的两种方法cv2.warpAffine和cv2.warpPerspective
本文链接:https://blog.csdn.net/qq_27261889/article/details/80720359 # usr/bin/env python # coding: utf- ...
- windows下获取IP地址的两种方法
windows下获取IP地址的两种方法: 一种可以获取IPv4和IPv6,但是需要WSAStartup: 一种只能取到IPv4,但是不需要WSAStartup: 如下: 方法一:(可以获取IPv4和I ...
- android 之 启动画面的两种方法
现在,当我们打开任意的一个app时,其中的大部分都会显示一个启动界面,展示本公司的logo和当前的版本,有的则直接把广告放到了上面.启动画面的可以分为两种设置方式:一种是两个Activity实现,和一 ...
- [转载]C#读写txt文件的两种方法介绍
C#读写txt文件的两种方法介绍 by 大龙哥 1.添加命名空间 System.IO; System.Text; 2.文件的读取 (1).使用FileStream类进行文件的读取,并将它转换成char ...
- php如何防止图片盗用/盗链的两种方法(转)
图片防盗链有什么用? 防止其它网站盗用你的图片,浪费你宝贵的流量.本文章向大家介绍php防止图片盗用/盗链的两种方法 Apache图片重定向方法 设置images目录不充许http访问 Apache服 ...
- WPF程序将DLL嵌入到EXE的两种方法
WPF程序将DLL嵌入到EXE的两种方法 这一篇可以看作是<Visual Studio 版本转换工具WPF版开源了>的续,关于<Visual Studio 版本转换工具WPF版开源了 ...
- MongoDB实现分页(两种方法)
1.插入实验数据 偷懒用下samus,100条. ; i < ; i++) { Document doc = new Document(); doc["ID"] = i; d ...
- css:图标与文字对齐的两种方法
(好久没写博客了,这几个月的积累比较零碎,记在本子上,现在开始整理归类) 在平时写页面的过程中,常遇到要把小图标与文字对齐的情况.比如: 总结了两种方法,代码量都比较少. 第一种 对img设置竖直方向 ...
随机推荐
- D - Sigma Function 1~n内有多少个约数和为偶数
/** 题目:D - Sigma Function 链接:https://vjudge.net/contest/154246#problem/D 题意:求1~n内约数和为偶数的数的个数. 思路:一个数 ...
- Nodejs各种功能Module的收集整理
收集整理接触过的各种常用的nodejs modules,不断更新~~~ ================================================================ ...
- Struts2 主题和模板
实际本章教程开始之前,让我们看看由http://struts.apache.org给出的几个定义: Term 描述 tag A small piece of code executed from wi ...
- ThinkPHP带表情无限级评论回复
今天就tp中(含表情)无限级评论回复做一个个人总结. 1.准备TP基本框架 2.数据库,数据表的建立 A.先说说数据库(表)的建立. a-1,数据库:blog a-2,数据表:bolg_comment ...
- db2 blob EMPTY_BLOB()
--针对BLOG类型的列,写入一个0长度的字符串
- javascript拼接html代码
转自开源中国社区:http://www.oschina.net/code/snippet_94055_21640经常做jsp开发的朋友可能遇到一个情况,显示列表数据不是table,而是div或者其他很 ...
- Java-iBATIS
1.是什么? 2010年迁移到了google code,并且改名为MyBatis.ibatis1.ibatis2.到了版本3就改名为mybatis. iBATIS的是一个持久层框架,它能够自动在 Ja ...
- Unix OpenCV安装
官方下载:https://sourceforge.net/projects/opencvlibrary/files/ 最好下载2.4.13版本,不然可能会有很多奇奇怪怪的问题 解压后: mkdir ...
- 学生成绩管理系统【c】
#include<stdio.h> #include<stdlib.h> #include<string.h> #include<conio.h> #d ...
- 【BZOJ4444】[Scoi2015]国旗计划 双指针+倍增
[BZOJ4444][Scoi2015]国旗计划 Description A国正在开展一项伟大的计划——国旗计划.这项计划的内容是边防战士手举国旗环绕边境线奔袭一圈.这项计划需要多名边防战士以接力的形 ...