须知

Stitcher 是 openCV 提供的一个图片拼接的类。 其 openCV 已经封装了很多, 我们只需要传入图片和拿到结果即可。 首先我们先对其能力进行了解和摸底及如果使用。

参考资料

https://docs.opencv.org/4.6.0/d2/d8d/classcv_1_1Stitcher.html#a37ee5bacf229e9d0fb9f97c8f5ed1acd
https://blog.csdn.net/windxgz/article/details/110792332

使用及方法说明

使用 Stitcher 就简单的拼接就是如下:

1
2
3
4
// 创建 Stitcher 对象
Ptr<Stitcher> stitcher = Stitcher::create();
// 进行拼接。 其中 mats 是我们输入的图片信息,mat 是输出的合并完成的图片信息。 返回值 status 是拼接状态。
Stitcher::Status state = stitcher->stitch(mats, *mat);

我们可以通过上面使用默认的参数进行拼接,通过经验, 那么肯定是可以进行配置参数去设置如果匹配的。 其设置如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// 将图像的缩放率控制在0-1之间,因为图像一般为三位数的边长,所以这样计算了一个比例将图像进行了缩放,相对的图像的细节与特征点的数量也就会变化,这个值越大则图像中的细节就越多,特征点也会越多
// 配准分辨率,这个值越小速度越快,但是特征就越少
stitcher->setRegistrationResol();

// 接缝尺度计算因子
// 接缝分辨率
stitcher->setSeamEstimationResol()

// 曝光
stitcher->setCompostitingResol();

// 置信度
stitcher->setPanoConfidenceThresh();

// 波形校正
stitcher->setWaveCorrection();

// 波形校正
stitcher->setWavecorrectKind()

// 特征查找
// 利用orb特征提取,速度比较快,但是sift和surf好更精确
stitcher->setFeaturesFinder()

// 特征配准器
stitcher->setFeaturesMatcher()

// 配准遮罩
stitcher->setMatchingMask()

// 相机参数优化
stitcher->setBundleAdjuster()

// 光照补偿分辨率
stitcher->setCompositingResol(0.5)

// 利用图割查找接缝线,图割有直接法和间接法,默认是直接法
stitcher->setSeamFinder(makePtr<detail::GraphCutSeamFinder>(detail::GraphCutSeamFinder::COST_COLOR))

// 多段混合算法
stitcher->setBlender(makePtr<detail::MultiBandBlender>(false))

// 基于单应性的旋转估计器
stitcher->setEstimator(makePtr<detail::HomographyBasedEstimator>())

// 球状变换
stitcher->setWarper(makePtr<SphericalWarper>())

stitcher->setExposureCompensator(makePtr<detail::BlocksGainCompensator>());

结果 status 的定义如下:

1
2
3
4
5
6
7
enum Status
{
OK = 0,
ERR_NEED_MORE_IMGS = 1,
ERR_HOMOGRAPHY_EST_FAIL = 2,
ERR_CAMERA_PARAMS_ADJUST_FAIL = 3
};