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设置竖直方向 ...
随机推荐
- spark集群模式
1.配置集群主机免登陆,参考http://www.cnblogs.com/puroc/p/5996730.html2.修改/etc/hosts文件,增加所有主机名和IP的对应关系 3.修改spark- ...
- error: not found: value sc
[问题] 解压spark的tar包后,执行bin/spark-shell,执行val lines=sc.textFile("README.md")时,抛错error: not fo ...
- 在linux虚机中装vmtools
很多用户在测试linux操作系统的时候喜欢用虚拟机,因为虚拟机方便而且可以同时在一台PC机上虚拟出来不同版本的linux操作系统,但是虚拟机和物理机之间的文件传输倒成了个问题,有人说可以使用vmtoo ...
- java.lang.IllegalArgumentException: column '_id' does not exist问题的解决方案
我在使用SimpleCursorAdapter的过程中遇到了问题: java.lang.IllegalArgumentException: column '_id' does not exist 这个 ...
- Wireshark使用注意事项
一直在使用老板的Wireshark,因为4G网络的逐步开通,越来越须要新版Wireshark来解析一些数据包. 在更换了新Wireshark的1.11.3后发现原来能够解析Gb口数据的NSIP不见了 ...
- Laragon集成开发环境+配置Xdebug+postman运行Xdebug
[ Laravel 5.5 文档 ] 快速入门 —— 使用 Laragon 在 Windows 中搭建 Laravel 开发环境:http://laravelacademy.org/post/7754 ...
- linux以下C 利用openssl的AES库加密,解密
OpenSSL提供了AES加解密算法的API const char *AES_options(void); AES算法状态,是所有支持或者是部分支持. 返回值:"aes(full)" ...
- mongo-connector来同步mongo
个人博客:https://blog.sharedata.info/ 最近需要做mongo之间的同步,因此还是选择之前的工具mongo-connectorgitHub文档:https://github. ...
- jpofiler监控JVM
1.官方下载地址,选择自己想要的版本 https://www.ej-technologies.com/download/jprofiler/version_92 2.分为linux服务端.window ...
- 42、使用存放在存assets文件夹下的SQLite数据库
因为这次的项目需要自带数据,所以就就把数据都放到一个SQLite的数据库文件中了,之后把该文件放到了assets文件夹下面.一开始打算每次都从assets文件夹下面把该文件夹拷贝到手机的SD卡或者手机 ...