旋转矩阵与旋转向量的相互转换

罗德里格斯公式

转轴 n 是矩阵 R 特征值 1 对应的特征向量。求解此方程,再归一化,就得到了旋转轴。

转换函数

void Rodrigues(const cv::Mat& src,cv::Mat dst,cv::Mat jacobian=0);

参数说明

  • src——为输入的旋转向量(3x1或者1x3)或者旋转矩阵(3x3)。该参数向量表示其旋转的角度,用向量长度表示。
  • dst——为输出的旋转矩阵(3x3)或者旋转向量(3x1或者1x3)。
  • jacobian——为可选的输出雅可比矩阵(3x9或者9x3),是输入与输出数组的偏导数。

图像变换

去畸变

针孔相机

调用方法

std::vector<cv::Point2f> inputDistortedPoints = ...
std::vector<cv::Point2f> outputUndistortedPoints;
cv::Mat cameraMatrix = ...
cv::Mat distCoeffs = ...cv::undistortPoints(inputDistortedPoints, outputUndistortedPoints, cameraMatrix, distCoeffs, cv::noArray(), cameraMatrix);

不要像下面这样调用,输出的点不正确

cv::undistortPoints(inputDistortedPoints, outputUndistortedPoints, cameraMatrix, distCoeffs)

鱼眼相机

cv::fisheye::undistortPoints(inputDistortedPoints, outputUndistortedPoints, cameraMatrix, distCoeffs, cv::noArray(), cameraMatrix);

投影

针孔相机

函数

void cv::projectPoints(InputArray objectPoints,InputArray rvec,InputArray tvec,InputArray cameraMatrix,InputArray distCoeffs,OutputArray imagePoints,OutputArray jacobian = noArray(),double aspectRatio = 0)

Parameters

objectPoints Array of object points expressed wrt. the world coordinate frame. A 3xN/Nx3 1-channel or 1xN/Nx1 3-channel (or vector<Point3f> ), where N is the number of points in the view.
rvec The rotation vector (Rodrigues) that, together with tvec, performs a change of basis from world to camera coordinate system, see calibrateCamera for details.
tvec The translation vector, see parameter description above.
cameraMatrix Camera intrinsic matrix
distCoeffs Input vector of distortion coefficients (k1,k2,p1,p2[,k3[,k4,k5,k6[,s1,s2,s3,s4[,τx,τy]]]]) of 4, 5, 8, 12 or 14 elements . If the vector is empty, the zero distortion coefficients are assumed.
imagePoints Output array of image points, 1xN/Nx1 2-channel, or vector<Point2f> .
jacobian Optional output 2Nx(10+<numDistCoeffs>) jacobian matrix of derivatives of image points with respect to components of the rotation vector, translation vector, focal lengths, coordinates of the principal point and the distortion coefficients. In the old interface different components of the jacobian are returned via different output parameters.
aspectRatio Optional "fixed aspect ratio" parameter. If the parameter is not 0, the function assumes that the aspect ratio ( fx/fy) is fixed and correspondingly adjusts the jacobian matrix.

示例

#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/highgui/highgui.hpp"#include <iostream>
#include <string>using namespace std;vector<cv::Point3f> Generate3DPoints();int main(int argc, char* argv[])
{// Read 3D pointsvector<cv::Point3f> objectPoints = Generate3DPoints();vector<cv::Point2f> imagePoints;cv::Mat intrisicMat(3, 3, cv::DataType<float>::type); // Intrisic matrixintrisicMat.at<float>(0, 0) = 1.6415318549788924e+003;intrisicMat.at<float>(1, 0) = 0;intrisicMat.at<float>(2, 0) = 0;intrisicMat.at<float>(0, 1) = 0;intrisicMat.at<float>(1, 1) = 1.7067753507885654e+003;intrisicMat.at<float>(2, 1) = 0;intrisicMat.at<float>(0, 2) = 5.3262822453148601e+002;intrisicMat.at<float>(1, 2) = 3.8095355839052968e+002;intrisicMat.at<float>(2, 2) = 1;cv::Mat rVec(3, 1, cv::DataType<float>::type); // Rotation vectorrVec.at<float>(0) = -3.9277902400761393e-002;rVec.at<float>(1) = 3.7803824407602084e-002;rVec.at<float>(2) = 2.6445674487856268e-002;cv::Mat tVec(3, 1, cv::DataType<float>::type); // Translation vectortVec.at<float>(0) = 2.1158489381208221e+000;tVec.at<float>(1) = -7.6847683212704716e+000;tVec.at<float>(2) = 2.6169795190294256e+001;cv::Mat distCoeffs(5, 1, cv::DataType<float>::type);   // Distortion vectordistCoeffs.at<float>(0) = -7.9134632415085826e-001;distCoeffs.at<float>(1) = 1.5623584435644169e+000;distCoeffs.at<float>(2) = -3.3916502741726508e-002;distCoeffs.at<float>(3) = -1.3921577146136694e-002;distCoeffs.at<float>(4) = 1.1430734623697941e-002;cout << "Intrisic matrix: " << intrisicMat << endl << endl;cout << "Rotation vector: " << rVec << endl << endl;cout << "Translation vector: " << tVec << endl << endl;cout << "Distortion coef: " << distCoeffs << endl << endl;std::vector<cv::Point2f> projectedPoints;cv::projectPoints(objectPoints, rVec, tVec, intrisicMat, distCoeffs, projectedPoints);cout << "Press any key to exit.";cin.ignore();cin.get();return 0;
}vector<cv::Point3f> Generate3DPoints()
{vector<cv::Point3f> points;points.push_back(cv::Point3f(.5, .5, -.5));points.push_back(cv::Point3f(.5, .5, .5));points.push_back(cv::Point3f(-.5, .5, .5));points.push_back(cv::Point3f(-.5, .5, -.5));points.push_back(cv::Point3f(.5, -.5, -.5));points.push_back(cv::Point3f(-.5, -.5, -.5));points.push_back(cv::Point3f(-.5, -.5, .5));for(unsigned int i = 0; i < points.size(); ++i){ cout << points[i] << endl << endl;}return points;
}

鱼眼相机

函数

// 提供了两个重载函数,经验上第一个容易崩溃,建议使用第二个
void cv::fisheye::projectPoints(InputArray objectPoints,OutputArray imagePoints,InputArray rvec,InputArray tvec,InputArray K,InputArray D,double alpha = 0,OutputArray jacobian = noArray())void cv::fisheye::projectPoints(InputArray objectPoints,OutputArray   imagePoints,const Affine3d& affine,InputArray K,InputArray D,double alpha = 0,OutputArray  jacobian = noArray())

Parameters

objectPoints Array of object points, 1xN/Nx1 3-channel (or vector<Point3f> ), where N is the number of points in the view.
imagePoints Output array of image points, 2xN/Nx2 1-channel or 1xN/Nx1 2-channel, or vector<Point2f>.
affine 仿射变换,可以使用位姿矩阵进行初始化
K Camera intrinsic matrix cameramatrixK.
D Input vector of distortion coefficients (k1,k2,k3,k4).
alpha The skew coefficient.
jacobian Optional output 2Nx15 jacobian matrix of derivatives of image points with respect to components of the focal lengths, coordinates of the principal point, distortion coefficients, rotation vector, translation vector, and the skew. In the old interface different components of the jacobian are returned via different output parameters.

参考文献

  • https://blog.csdn.net/lyq_12/article/details/82800790
  • https://blog.csdn.net/weixin_42905141/article/details/100677949
  • https://docs.opencv.org/3.4/d9/d0c/group__calib3d.html#ga1019495a2c8d1743ed5cc23fa0daff8c
  • https://docs.opencv.org/3.4/db/d58/group__calib3d__fisheye.html#ga719a1b99cd5cb1fec92d0d1aedbb6841
  • https://blog.csdn.net/qq_15505637/article/details/76197820

OpenCV位姿与投影变换相关推荐

  1. 使用 OpenCV 进行图像投影变换

    投影变换(仿射变换) 在数学中,线性变换是将一个向量空间映射到另一个向量空间的函数,通常由矩阵实现.如果映射保留向量加法和标量乘法,则映射被认为是线性变换. 要将线性变换应用于向量(即,一个点的坐标, ...

  2. 使用OpenCV透视变换技术实现坐标变换实践

    1. 概述 1.1. 需求 在局部空间(无GPS定位)视频监控过程中,把视频识别到物体位置,投射到空间平面坐标系中,获取物体在局部空间的平面坐标. 1.2. 解决方案 使用图像透视变换技术. 1.3. ...

  3. 【图像处理】——特征匹配(SIFT特征检测器+FLANN特征匹配方法+KNN近邻最优匹配筛选)——cv.xfeatures2d.SIFT_create()sift.detectAndCompute

    转载请注明地址 目录 1.特征检测和特征匹配方法 (1)特征检测算法 (2)特征匹配算法 (3)各种特征检测算法的比较 2.特征匹配的基本步骤(附带主要的函数) (1)图像预处理--灰度化(模板--查 ...

  4. 一些可以参考的文档集合7

    之前的文章集合: 一些可以参考文章集合1_xuejianxinokok的博客-CSDN博客 一些可以参考文章集合2_xuejianxinokok的博客-CSDN博客 一些可以参考的文档集合3_xuej ...

  5. 音视频技术开发周刊 | 260

    每周一期,纵览音视频技术领域的干货. 新闻投稿:contribute@livevideostack.com. LiveVideoStackCon 2022 北京站讲师招募开始啦! 11月4-5日,Li ...

  6. Opencv——几何空间变换(仿射变换和投影变换)

    几何空间变换 [1]几何变换(空间变换)简述 [2]变换矩阵知识简述 齐次坐标的概念 几何运算矩阵 [3]图像的仿射变换 1.平移变换 2.比例缩放 3.旋转 4.对称变换(不做展示) 1.关于X轴变 ...

  7. 【OpenCV 例程200篇】35. 图像的投影变换(边界填充)

    [OpenCV 例程200篇]35. 图像的投影变换(边界填充) 欢迎关注 『OpenCV 例程200篇』 系列,持续更新中 欢迎关注 『Python小白的OpenCV学习课』 系列,持续更新中 投影 ...

  8. opencv计算物体姿态旋转_物体的三维识别与6D位姿估计:PPF系列论文介绍(五)...

    点击上方"3D视觉工坊",选择"星标" 干货第一时间送达 本文创新点: 点对特征是一种广泛应用的检测点云中三维物体的方法,但在存在传感器噪声和背景杂波的情况下, ...

  9. OpenCV中的「透视变换 / 投影变换 / 单应性」—cv.warpPerspective、cv.findHomography

    文章目录 引言 透视变换(projective transform) 单应性(Homography) opencv代码 仿射变换相关函数 投影变换相关的函数 鸟瞰图代码示例 小结 引言 图像的几何变换 ...

最新文章

  1. php导出excel格式数据
  2. Python 10 MySQL数据库(一)
  3. datetime模块及time模块
  4. 5.2 Redis商业版
  5. 5折交叉验证_交叉验证的方法主要分为哪些?
  6. 《一天搞懂深度学习》下载
  7. 三菱PLC与上位机进行通讯
  8. 公务员计算机职称有哪些,2017职称考试有哪些
  9. 《认文识字•简述》【小结】
  10. 微信小程序视图控件与bindtap之间的问题的解决
  11. SAAS的概念及优缺点
  12. cyk的小学数学题 小学数学
  13. Qt跨平台框架在金融领域必然性
  14. 【 西交,西工大,西北大学计算机考研专硕2023详细信息】
  15. vue开发,iview日期选择验证
  16. 提取了下刘汝佳推荐的题号...
  17. 在32位、64位操作系统下各数据类型所占的字节数
  18. 大白菜U盘装系统综合教程
  19. 转转闲鱼交易猫源码搭建
  20. 【机器学习】了解这12个机器学习核心知识点,轻松玩转机器学习项目。

热门文章

  1. OSChina 周二乱弹 ——同意,我的元首大人
  2. Git Flow—Git团队协作最佳实践
  3. MYSQL实现ORDER BY LIMIT的方法以及优先队列(堆排序)
  4. Saltstack 用户管理
  5. 如何解决资料下载下来为index.html和PHP文件的问题?
  6. esl8266开发之旅_从ESL老师到越南软件开发人员的旅程
  7. 如何使用React.js和Heroku快速实现从想法到URL的转变
  8. 如何使用Web Audio API听到“ Yanny”和“ Laurel”的声音
  9. Spark的基础应用
  10. java中判断两个字符(或者字符串相等)