![3f459471-2c13-eb11-8da9-e4434bdf6706.png](http://p02.5ceimg.com/content/3f459471-2c13-eb11-8da9-e4434bdf6706.png)
目录:
- 函数介绍
- 图像拼接算法实现
- 图像拼接算法改进
本文参考上面这个链接,实现多张图像的拼接,构建一张全景图。
根据多个图像创建全景图的步骤为:
- 检测两张图像的关键点特征(DoG、Harris等)
- 计算不变特征描述符(SIFT、SURF或ORB等)
- 根据关键点特征和描述符,对两张图像进行匹配,得到若干匹配点对,并移除错误匹配;
- 使用Ransac算法和匹配的特征来估计单应矩阵(homography matrix);
- 通过单应矩阵来对图像进行仿射变换;
- 两图像拼接,重叠部分融合;
- 裁剪以获得美观的最终图像。
原理比较复杂,本文先不讲解,OpenCV中已经实现了全景图拼接的算法,它们是 cv2.createStitcher
(OpenCV 3.x) 和 cv2.Stitcher_create
(OpenCV 4) 。
该算法对以下条件具有较好的鲁棒性:
- 输入图像的顺序
- 图像的方向
- 光照变化
- 图像噪声
一、函数介绍
OpenCV 3.x 的 cv2.createStitcher 函数原型为:
createStitcher(...)
createStitcher([, try_use_gpu]) -> retval
这个函数有一个参数 try_use_gpu
,它可以用来提升图像拼接整个过程的速度。
OpenCV 4 的 cv2.Stitcher_create 函数原型为:
Stitcher_create(...)
Stitcher_create([, mode]) -> retval
. @brief Creates a Stitcher configured in one of the stitching
. modes.
.
. @param mode Scenario for stitcher operation. This is usually
. determined by source of images to stitch and their transformation.
. Default parameters will be chosen for operation in given scenario.
. @return Stitcher class instance.
要执行实际的图像拼接,我们需要调用 .stitch
方法:
OpenCV 3.x:
stitch(...) method of cv2.Stitcher instance
stitch(images[, pano]) -> retval, pano
O