我是靠谱客的博主 会撒娇西牛,这篇文章主要介绍ViSP学习笔记(二十四):计算两幅图像之间的单应性矩阵,现在分享给大家,希望可以做个参考。

开发环境:Ubuntu 18.04 LTS + ROS Melodic + ViSP 3.3.1
文章内容主要参考ViSP官方教学文档:https://visp-doc.inria.fr/doxygen/visp-daily/tutorial_mainpage.html

  本文主要介绍了如何使用ViSP计算两幅图像之间的单应性矩阵,在已知同一个物体的特征点在两个相机中的图像坐标后,就能够计算两个相机坐标之间的单应性矩阵。如果能够保证两幅图像中的特征点是一一对应匹配的可以采用DLT或HLM算法进行计算。本文主要参考了computer-vision中的tutorial-homography-from-points.cpp例程。首先要获取这个例程文件并编译它

复制代码
1
2
3
4
5
6
7
svn export https://github.com/lagadic/visp.git/trunk/tutorial/computer-vision cd computer-vision/ mkdir build cd build cmake .. -DCMAKE_BUILD_TYPE=Release -DVISP_DIR=$VISP_WS/visp-build make

  执行例程,查看效果

复制代码
1
2
./tutorial-homography-from-points

  首先会输出两个相机坐标系之间的单应性矩阵(分别使用DLT和HLM两种算法)

复制代码
1
2
3
4
5
6
7
8
9
10
Estimated homography using DLT: 0.9540353246 -0.0911338709 0.5155021269 0.04848747565 0.9605117258 -0.03003809211 -0.3066184621 -0.03490122576 1 Estimated homography using HLM: 0.9540353246 -0.0911338709 0.5155021269 0.04848747565 0.9605117258 -0.03003809211 -0.3066184621 -0.03490122576 1

  然后将单应性矩阵拆分成旋转矩阵和平移矩阵

复制代码
1
2
3
4
5
6
Estimated displacement: atb: 0.2016519874 -0.1008259937 0.1008259937 athetaub: -3 20 5 n: 0.2588190451 -7.938094626e-15 0.9659258263

  最后给出特征点的输入坐标和估计坐标结果

复制代码
1
2
3
4
5
Ground truth: Point 3 in pixels in frame b: 377.9450564, 193.9928711 Ground truth: Point 3 in pixels in frame a: 353.8501593, 486.1851856 Estimation from homography: Point 3 in pixels in frame a: 353.8501593, 486.1851856

  下面介绍一下代码实现过程

复制代码
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
50
51
52
53
#include <visp3/vision/vpHomography.h> #include <visp3/core/vpMeterPixelConversion.h> int main() { double L = 0.1; std::vector<vpPoint> oP;//新建目标空间坐标容器 //初始化目标特征点的空间坐标 oP.push_back(vpPoint(-L, -L, 0)); oP.push_back(vpPoint(2 * L, -L, 0)); oP.push_back(vpPoint(L, 3 * L, 0)); oP.push_back(vpPoint(-L, 4 * L, 0)); vpHomogeneousMatrix bMo(0.1, 0, 1, 0, vpMath::rad(15), 0);//设置目标坐标系和相机b坐标系之间的齐次变换矩阵 vpHomogeneousMatrix aMb(0.2, -0.1, 0.1, vpMath::rad(-3), vpMath::rad(20), vpMath::rad(5));//设置相机a坐标系和相机b坐标系之间的齐次变换矩阵 vpHomogeneousMatrix aMo = aMb * bMo;//计算目标坐标系和相机a坐标系之间的齐次变换矩阵 std::vector<vpPoint> aP(4), bP(4);//新建两个相机的图像坐标容器 std::vector<double> xa(4), ya(4), xb(4), yb(4);//新建两个相机的图像x和y坐标容器 for (unsigned int i = 0; i < 4; i++) { oP[i].project(aMo);//根据相机和目标坐标系之间的齐次变换矩阵 与 特征点空间坐标计算得到图像坐标 xa[i] = oP[i].get_x(); ya[i] = oP[i].get_y(); oP[i].project(bMo); xb[i] = oP[i].get_x(); yb[i] = oP[i].get_y(); } vpHomography aHb; vpHomography::DLT(xb, yb, xa, ya, aHb, true);//利用DLT算法计算单应性矩阵 std::cout << "Estimated homography using DLT:n" << aHb / aHb[2][2] << std::endl; vpHomography::HLM(xb, yb, xa, ya, true, aHb);//利用HLM算法计算单应性矩阵 std::cout << "Estimated homography using HLM:n" << aHb / aHb[2][2] << std::endl; vpRotationMatrix aRb; vpTranslationVector atb; vpColVector n; aHb.computeDisplacement(aRb, atb, n);//把单应性矩阵分解为平移矩阵和旋转矩阵 std::cout << "nEstimated displacement:" << std::endl; std::cout << " atb: " << atb.t() << std::endl; vpThetaUVector atub; atub.buildFrom(aRb); std::cout << " athetaub: "; for (unsigned int i = 0; i < 3; i++) std::cout << vpMath::deg(atub[i]) << " "; std::cout << std::endl; std::cout << " n: " << n.t() << std::endl; vpImagePoint iPa, iPb; vpCameraParameters cam; vpMeterPixelConversion::convertPoint(cam, xb[3], yb[3], iPb); vpMeterPixelConversion::convertPoint(cam, xa[3], ya[3], iPa); std::cout << "Ground truth: Point 3 in pixels in frame b: " << iPb << std::endl; std::cout << "Ground truth: Point 3 in pixels in frame a: " << iPa << std::endl; // Project the position in pixel of point 3 from the homography std::cout << "Estimation from homography: Point 3 in pixels in frame a: " << vpHomography::project(cam, aHb, iPb) << std::endl;//根据单应性矩阵和特征点在相机b坐标系下的坐标估计特征点在相机a坐标系下的坐标 }

如果大家对于深度学习与计算机视觉领域感兴趣,希望获得更多的知识分享与最新的论文解读,欢迎关注我的个人公众号“深视”。在这里插入图片描述

最后

以上就是会撒娇西牛最近收集整理的关于ViSP学习笔记(二十四):计算两幅图像之间的单应性矩阵的全部内容,更多相关ViSP学习笔记(二十四):计算两幅图像之间内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(92)

评论列表共有 0 条评论

立即
投稿
返回
顶部