显示相机的位姿

——视觉SLAM十四讲 Page 69

运行结果(GIF动图):


Readme.txt

1. How to compile this program:* use pangolin: slambook/3rdpart/Pangolin or download it from github: https://github.com/stevenlovegrove/Pangolin* install dependency for pangolin (mainly the OpenGL):
sudo apt-get install libglew-dev* compile and install pangolin
cd [path-to-pangolin]
mkdir build
cd build
cmake ..
make
sudo make install * compile this program:
mkdir build
cd build
cmake ..
make * run the build/visualizeGeometry2. How to use this program:The UI in the left panel displays different representations of T_w_c ( camera to world ). It shows the rotation matrix, tranlsation vector, euler angles (in roll-pitch-yaw order) and the quaternion.
Drag your left mouse button to move the camera, right button to rotate it around the box, center button to rotate the camera itself, and press both left and right button to roll the view.
Note that in this program the original X axis is right (red line), Y is up (green line) and Z in back axis (blue line). You (camera) are looking at (0,0,0) standing on (3,3,3) at first. 3. Problems may happen:
* I found that in virtual machines there may be an error in pangolin, which was solved in its issue: https://github.com/stevenlovegrove/Pangolin/issues/74 . You need to comment the two lines mentioned by paulinus, and the recompile and reinstall Pangolin, if you happen to find this problem. If you still have problems using this program, please contact: gaoxiang12@mails.tsinghua.edu.cn

CMakeLists.txt

cmake_minimum_required( VERSION 2.8 )
project( visualizeGeometry )set(CMAKE_CXX_FLAGS "-std=c++11")# 添加Eigen头文件
include_directories( "/usr/include/eigen3" )# 添加Pangolin依赖
find_package( Pangolin )
include_directories( ${Pangolin_INCLUDE_DIRS} )add_executable( visualizeGeometry visualizeGeometry.cpp )
target_link_libraries( visualizeGeometry ${Pangolin_LIBRARIES} )

visualizeGeometry.cpp

#include <iostream>
#include <iomanip>using namespace std;#include <Eigen/Core>
#include <Eigen/Geometry>using namespace Eigen;#include <pangolin/pangolin.h>struct RotationMatrix {Matrix3d matrix = Matrix3d::Identity();
};ostream &operator<<(ostream &out, const RotationMatrix &r) {out.setf(ios::fixed);Matrix3d matrix = r.matrix;out << '=';out << "[" << setprecision(2) << matrix(0, 0) << "," << matrix(0, 1) << "," << matrix(0, 2) << "],"<< "[" << matrix(1, 0) << "," << matrix(1, 1) << "," << matrix(1, 2) << "],"<< "[" << matrix(2, 0) << "," << matrix(2, 1) << "," << matrix(2, 2) << "]";return out;
}istream &operator>>(istream &in, RotationMatrix &r) {return in;
}struct TranslationVector {Vector3d trans = Vector3d(0, 0, 0);
};ostream &operator<<(ostream &out, const TranslationVector &t) {out << "=[" << t.trans(0) << ',' << t.trans(1) << ',' << t.trans(2) << "]";return out;
}istream &operator>>(istream &in, TranslationVector &t) {return in;
}struct QuaternionDraw {Quaterniond q;
};ostream &operator<<(ostream &out, const QuaternionDraw quat) {auto c = quat.q.coeffs();out << "=[" << c[0] << "," << c[1] << "," << c[2] << "," << c[3] << "]";return out;
}istream &operator>>(istream &in, const QuaternionDraw quat) {return in;
}int main(int argc, char **argv) {pangolin::CreateWindowAndBind("visualize geometry", 1000, 600);glEnable(GL_DEPTH_TEST);pangolin::OpenGlRenderState s_cam(pangolin::ProjectionMatrix(1000, 600, 420, 420, 500, 300, 0.1, 1000),pangolin::ModelViewLookAt(3, 3, 3, 0, 0, 0, pangolin::AxisY));const int UI_WIDTH = 500;pangolin::View &d_cam = pangolin::CreateDisplay().SetBounds(0.0, 1.0, pangolin::Attach::Pix(UI_WIDTH), 1.0, -1000.0f / 600.0f).SetHandler(new pangolin::Handler3D(s_cam));// uipangolin::Var<RotationMatrix> rotation_matrix("ui.R", RotationMatrix());pangolin::Var<TranslationVector> translation_vector("ui.t", TranslationVector());pangolin::Var<TranslationVector> euler_angles("ui.rpy", TranslationVector());pangolin::Var<QuaternionDraw> quaternion("ui.q", QuaternionDraw());pangolin::CreatePanel("ui").SetBounds(0.0, 1.0, 0.0, pangolin::Attach::Pix(UI_WIDTH));while (!pangolin::ShouldQuit()) {glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);d_cam.Activate(s_cam);pangolin::OpenGlMatrix matrix = s_cam.GetModelViewMatrix();Matrix<double, 4, 4> m = matrix;RotationMatrix R;for (int i = 0; i < 3; i++)for (int j = 0; j < 3; j++)R.matrix(i, j) = m(j, i);rotation_matrix = R;TranslationVector t;t.trans = Vector3d(m(0, 3), m(1, 3), m(2, 3));t.trans = -R.matrix * t.trans;translation_vector = t;TranslationVector euler;euler.trans = R.matrix.eulerAngles(2, 1, 0);euler_angles = euler;QuaternionDraw quat;quat.q = Quaterniond(R.matrix);quaternion = quat;glColor3f(1.0, 1.0, 1.0);pangolin::glDrawColouredCube();// draw the original axisglLineWidth(3);glColor3f(0.8f, 0.f, 0.f);glBegin(GL_LINES);glVertex3f(0, 0, 0);glVertex3f(10, 0, 0);glColor3f(0.f, 0.8f, 0.f);glVertex3f(0, 0, 0);glVertex3f(0, 10, 0);glColor3f(0.2f, 0.2f, 1.f);glVertex3f(0, 0, 0);glVertex3f(0, 0, 10);glEnd();pangolin::FinishFrame();}
}

视觉SLAM-显示相机的位姿相关推荐

  1. 视觉SLAM学习--相机成像模型及标定

    相机模型1:B站热心网友的视频讲解,比较清楚 链接:https://www.bilibili.com/video/BV1Rh411o7Jb/?spm_id_from=333.788.recommend ...

  2. 初识视觉SLAM 用相机解决定位和建图问题

    分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow 也欢迎大家转载本篇文章.分享知识,造福人民,实现我们中华民族伟大复兴! 引言:视 ...

  3. SLAM学习--------相机位姿表示-李群李代数

    slam 求解相机的位姿求解核心思想:将有约束的李群问题转换成无约束的李代数问题,然后使用高斯牛顿算法或者LM(列文伯格-马夸尔特法)求解. 人们找了很多以相机位姿为变量的误差函数,比如光度误差,重投 ...

  4. 视觉SLAM十四讲学习笔记-第三讲-相似、仿射、射影变换和eigen程序、可视化演示

    专栏系列文章如下: 视觉SLAM十四讲学习笔记-第一讲_goldqiu的博客-CSDN博客 视觉SLAM十四讲学习笔记-第二讲-初识SLAM_goldqiu的博客-CSDN博客 视觉SLAM十四讲学习 ...

  5. 【视觉SLAM十四讲】第一章理论详解

    文章目录 第一讲 概述与预备知识 SLAM是什么 室内/室外定位 稀疏-半稠密重建 稠密重建 SLAM可以用在哪些地方? **作业1.** SLAM会在哪些场合中⽤到?⾄少列举三个⽅向. SLAM: ...

  6. SLAM综述:激光雷达与视觉SLAM

    第一节概述. 第二节讲述激光SLAM:激光传感器,开源系统,深度学习的应用. 第三节讲述视觉SLAM:相机传感器,开源系统,视觉惯性里程计,深度学习的应用. 第四节讲述激光雷达与视觉的融合. 最后展望 ...

  7. 视觉SLAM常见面试题 (下)

    常见面试题 1.   视觉SLAM框架及组成 a) SLAM即实时定位建图,按照使用的传感器分为激光SLAM(LOAM.V-LOAM.cartographer.gmapping)与视觉SLAM,其中视 ...

  8. 视觉SLAM综述(入门篇)

      最近几天刚刚接触到视觉SLAM这个研究方向,发现这个方向的知识点挺多挺杂的,于是就自己看文献,刷博客,大致对视觉SLAM有了整体的了解.   这篇博客也算是一个简单的小综述,具体的知识点正在学习之 ...

  9. 【视觉SLAM】An Improved ORB-SLAM2 in Dynamic Scene with Instance Segmentation

    Cite: H. Qian and P. Ding.An Improved ORB-SLAM2 in Dynamic Scene with Instance Segmentation[C].2019 ...

最新文章

  1. CSS + DIV 让页脚始终底部
  2. VMware 虚拟化编程(5) — VixDiskLib 虚拟磁盘库详解之一
  3. PrimerCH3字符串,向量,迭代器,数组
  4. ajax常见错误和使用总结
  5. sql查询php,SQL查询或PHP?
  6. Nginx的开启和关闭
  7. 数据库系统中数据抽象的三级结构
  8. TDL(HDU-6641)
  9. Erlang 基础学习笔记
  10. 如何在vue项目中使用md5加密
  11. Unet实现文档图像去噪、去水印
  12. radon变换(c++、OpenCV实现)
  13. 12.30天自动登陆
  14. Multisim14.0仿真:三相半波可控整流电路
  15. 为什么128KB的魂斗罗可以塞下这么长的剧情?
  16. Hang Detect 问题分析案例
  17. Cisco(思科)配置代码<根据学习进度持续跟新>
  18. zzuliloj 1037: 四则运算
  19. HTML基础知识(四)——浮动
  20. miracast技术详解

热门文章

  1. 基于JAVA+SpringMVC+Mybatis+MYSQL的疫情防控物业管理系统
  2. 基于JAVA+SpringMVC+Mybatis+MYSQL的在线超市管理系统
  3. (转)从开发小白到音视频专家
  4. 在才开始进入前端这个坑的时候 在布局中会遇到很多问题 我才入这个坑的时候 在margin top 中遇到几个bug 我分享一下...
  5. Clojure学习之比线性箭头操作
  6. 论文阅读(XiangBai——【AAAI2017】TextBoxes_A Fast Text Detector with a Single Deep Neural Network)...
  7. socket编程 —— 非阻塞socket (转)---例子已上传至文件中
  8. DOCKER功能练习
  9. ShellExecuteA URLDownloadToFileA
  10. filetype 在搜索引擎中的使用方法(2)