OpenCv实现两幅图像的拼接
直接贴上源码
来源:http://www.myexception.cn/image/1498389.html
实验效果
Left.jpg
right.jpg
ImageMatch.jpg
#include <iostream>
#include <iomanip>
#include "opencv2/core/core.hpp"
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/nonfree/nonfree.hpp"
#include "opencv2/imgproc/imgproc_c.h"
#include "opencv2/legacy/legacy.hpp"
#include "opencv2/legacy/compat.hpp"
using namespace cv;
using namespace std; int main()
{
Mat leftImg=imread("left.jpg");
Mat rightImg=imread("right.jpg");
if(leftImg.data==NULL||rightImg.data==NULL)
return ; //转化成灰度图
Mat leftGray;
Mat rightGray;
cvtColor(leftImg,leftGray,CV_BGR2GRAY);
cvtColor(rightImg,rightGray,CV_BGR2GRAY); //获取两幅图像的共同特征点 int minHessian=;
SurfFeatureDetector detector(minHessian);
vector<KeyPoint> leftKeyPoints,rightKeyPoints;
detector.detect(leftGray,leftKeyPoints);
detector.detect(rightGray,rightKeyPoints);
SurfDescriptorExtractor extractor;
Mat leftDescriptor,rightDescriptor;
extractor.compute(leftGray,leftKeyPoints,leftDescriptor);
extractor.compute(rightGray,rightKeyPoints,rightDescriptor);
FlannBasedMatcher matcher;
vector<DMatch> matches;
matcher.match(leftDescriptor,rightDescriptor,matches);
int matchCount=leftDescriptor.rows; if(matchCount>)
{
matchCount=;
//sort(matches.begin(),matches.begin()+leftDescriptor.rows,DistanceLessThan);
sort(matches.begin(),matches.begin()+leftDescriptor.rows);
} vector<Point2f> leftPoints;
vector<Point2f> rightPoints; for(int i=; i<matchCount; i++)
{
leftPoints.push_back(leftKeyPoints[matches[i].queryIdx].pt);
rightPoints.push_back(rightKeyPoints[matches[i].trainIdx].pt);
} //获取左边图像到右边图像的投影映射关系
Mat homo=findHomography(leftPoints,rightPoints);
Mat shftMat=(Mat_<double>(,)<<1.0,,leftImg.cols, ,1.0,, ,,1.0); //拼接图像
Mat tiledImg;
warpPerspective(leftImg,tiledImg,shftMat*homo,Size(leftImg.cols+rightImg.cols,rightImg.rows));
rightImg.copyTo(Mat(tiledImg,Rect(leftImg.cols,,rightImg.cols,rightImg.rows))); //保存图像
imwrite("tiled.jpg",tiledImg);
//显示拼接的图像
imshow("tiled image",tiledImg);
waitKey();
return ;
}
OpenCv实现两幅图像的拼接的更多相关文章
- Opencv实现两幅图像融合
实现两幅图像线性(不同系数下)的融合涉及到Opencv中两个关键的方法,addWeighted()和createTrackbar() addWeighted方法: 函数原型: void addWeig ...
- OpenCV --- 实现两幅图像并排合并(ROI)
Mat img1 = imread("1.png"); Mat img2 = imread("2.png"); int height = img1.rows; ...
- OpenCV 对两幅图像求和(求混合(blending))
#include <cv.h> #include <highgui.h> #include <iostream> using namespace cv; int m ...
- OpenCV,计算两幅图像的单应矩阵
平面射影变换是关于其次3维矢量的一种线性变换,可以使用一个非奇异的$3 \times 3$矩阵H表示,$X' = HX$,射影变换也叫做单应(Homography).计算出两幅图像之间的单应矩阵H,那 ...
- 【OpenCV学习】计算两幅图像的重叠区域
问题描述:已知两幅图像Image1和Image2,计算出两幅图像的重叠区域,并在Image1和Image2标识出重叠区域. 算法思想: 若两幅图像存在重叠区域,则进行图像匹配后,会得到一张完整的全景图 ...
- CV 两幅图像配准
http://www.cnblogs.com/Lemon-Li/p/3504717.html 图像配准算法一般可分为: 一.基于图像灰度统计特性配准算法:二.基于图像特征配准算法:三.基于图像理解的配 ...
- opencv::将两幅图像合并后,在同一个窗口显示;并将合并的图像流保存成视频文件
/** * @file main-opencv.cpp * @date July 2014 * @brief An exemplative main file for the use of ViBe ...
- OpenCV 学习笔记(0)两幅图像标定配准
参考教程 依赖opencv扩展库,使用sifi匹配 保存配准信息 "./config/calibratedPara.yaml" #include <iostream> ...
- 在Opencv中将一幅图像均分成M* N个小图像
std::vector<std::vector<Mat> > partitionImage(Mat&src,int rows,int cols) 函数中有三个输入参数, ...
随机推荐
- 通过分析 JDK 源代码研究 TreeMap 红黑树算法实现
本文转载自http://www.ibm.com/developerworks/cn/java/j-lo-tree/ 目录: TreeSet 和 TreeMap 的关系 TreeMap 的添加节点 Tr ...
- splice 很好用
splice 类似一个 copy pos 和 delete的组合拳,用起来很方便. arrayObject.splice(index,howmany,item1,.....,itemX) // ind ...
- C# 数据库查询总结
首先创建了一个SQL Server数据库作为测试的数据库,建立表并填入测试数据 数据库:SQL Server 数据库名:Blog 表名:Test 注:数据库的连接可以使用“dbl”文件测试,具体使用百 ...
- Metro各种流转换
Ibuffer转byte[] ,(int)buffer.Length); Byte[]转Ibuffer WindowsRuntimeBufferExtensions.AsBuffer(bytes,,b ...
- 【leetcode】 Unique Path ||(easy)
Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...
- xp系统打开软件程序总是弹出警告窗口,很烦人对不,怎么办呢?进来看
为了不浪费比较着急的朋友的的时间,先把解决方案说了,下面我在细说: 细说: 今天装了个xp的虚拟机,为了不在xp里重复装真机(win7的)里已经有的软件,就把我的工具盘共享给了虚拟机,大部分软件都可以 ...
- 【Mongodb】3.X 配置身份验证
配置身份验证详解: 开启认证: 启动MongoDB./mongodb --syslog --fork --port 20000 --auth 1.如果不添加参数:auth,表明用默认的root的权限 ...
- Lattice Diamond 和 ispLEVER 的不同之处
Lattice Diamond 和 ispLEVER.有一些不同,尤其是如何管理工程的不同,包括以下几点: 1.ispLEVER 有多种工程类型,不同的程序文件类型需要不同的类型的工程:但是Diamo ...
- Quartus 11.0 的AS 下载方式和JTAG下载jic文件的方式
FPGA下载的三种方式:主动配置方式(AS)和被动配置方式(PS)和最常用的(JTAG)配置方式: AS由FPGA器件引导配置操作过程,它控制着外部存储器和初始化过程,EPCS系列.如EPCS1,EP ...
- Enter password for default keyring to unlock
file /home/ok/.gnome2/keyrings/login.keyring /home/ok/.gnome2/keyrings/login.keyring: GNOME keyring, ...