OpenCV 位姿与投影变换
1. 旋转矩阵与旋转向量的相互转换1.1. 罗德里格斯公式符号^是向量到反对称的转换符。反之我们也可以计算从一个旋转矩阵到旋转向量的转换。对于转角θ有因此关于转轴n由于旋转轴上的向量在旋转后不发生改变说明转轴 n 是矩阵 R 特征值 1 对应的特征向量。求解此方程再归一化就得到了旋转轴。1.2. 转换函数void Rodrigues(const cv::Mat srccv::Mat dstcv::Mat jacobian0);参数说明src——为输入的旋转向量3x1或者1x3或者旋转矩阵3x3。该参数向量表示其旋转的角度用向量长度表示。dst——为输出的旋转矩阵3x3或者旋转向量3x1或者1x3。jacobian——为可选的输出雅可比矩阵3x9或者9x3是输入与输出数组的偏导数。2. 图像变换2.1. 去畸变2.1.1. 针孔相机调用方法std::vectorcv::Point2f inputDistortedPoints ... std::vectorcv::Point2f outputUndistortedPoints; cv::Mat cameraMatrix ... cv::Mat distCoeffs ... cv::undistortPoints(inputDistortedPoints, outputUndistortedPoints, cameraMatrix, distCoeffs, cv::noArray(), cameraMatrix);不要像下面这样调用输出的点不正确cv::undistortPoints(inputDistortedPoints, outputUndistortedPoints, cameraMatrix, distCoeffs2.1.2. 鱼眼相机cv::fisheye::undistortPoints(inputDistortedPoints, outputUndistortedPoints, cameraMatrix, distCoeffs, cv::noArray(), cameraMatrix);2.2. 投影2.2.1. 针孔相机函数void cv::projectPoints(InputArray objectPoints, InputArray rvec, InputArray tvec, InputArray cameraMatrix, InputArray distCoeffs, OutputArray imagePoints, OutputArray jacobian noArray(), double aspectRatio 0)ParametersobjectPointsArray of object points expressed wrt. the world coordinate frame. A 3xN/Nx3 1-channel or 1xN/Nx1 3-channel (or vectorPoint3f), where N is the number of points in the view.rvecThe rotation vector (Rodrigues) that, together with tvec, performs a change of basis from world to camera coordinate system, see calibrateCamera for details.tvecThe translation vector, see parameter description above.cameraMatrixCamera intrinsic matrixdistCoeffsInput 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.imagePointsOutput array of image points, 1xN/Nx1 2-channel, or vectorPoint2f .jacobianOptional output 2Nx(10numDistCoeffs) 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.aspectRatioOptional 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; vectorcv::Point3f Generate3DPoints(); int main(int argc, char* argv[]) { // Read 3D points vectorcv::Point3f objectPoints Generate3DPoints(); vectorcv::Point2f imagePoints; cv::Mat intrisicMat(3, 3, cv::DataTypefloat::type); // Intrisic matrix intrisicMat.atfloat(0, 0) 1.6415318549788924e003; intrisicMat.atfloat(1, 0) 0; intrisicMat.atfloat(2, 0) 0; intrisicMat.atfloat(0, 1) 0; intrisicMat.atfloat(1, 1) 1.7067753507885654e003; intrisicMat.atfloat(2, 1) 0; intrisicMat.atfloat(0, 2) 5.3262822453148601e002; intrisicMat.atfloat(1, 2) 3.8095355839052968e002; intrisicMat.atfloat(2, 2) 1; cv::Mat rVec(3, 1, cv::DataTypefloat::type); // Rotation vector rVec.atfloat(0) -3.9277902400761393e-002; rVec.atfloat(1) 3.7803824407602084e-002; rVec.atfloat(2) 2.6445674487856268e-002; cv::Mat tVec(3, 1, cv::DataTypefloat::type); // Translation vector tVec.atfloat(0) 2.1158489381208221e000; tVec.atfloat(1) -7.6847683212704716e000; tVec.atfloat(2) 2.6169795190294256e001; cv::Mat distCoeffs(5, 1, cv::DataTypefloat::type); // Distortion vector distCoeffs.atfloat(0) -7.9134632415085826e-001; distCoeffs.atfloat(1) 1.5623584435644169e000; distCoeffs.atfloat(2) -3.3916502741726508e-002; distCoeffs.atfloat(3) -1.3921577146136694e-002; distCoeffs.atfloat(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::vectorcv::Point2f projectedPoints; cv::projectPoints(objectPoints, rVec, tVec, intrisicMat, distCoeffs, projectedPoints); cout Press any key to exit.; cin.ignore(); cin.get(); return 0; } vectorcv::Point3f Generate3DPoints() { vectorcv::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; }2.2.2. 鱼眼相机函数// 提供了两个重载函数经验上第一个容易崩溃建议使用第二个 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())ParametersobjectPointsArray of object points, 1xN/Nx1 3-channel (or vectorPoint3f), where N is the number of points in the view.imagePointsOutput array of image points, 2xN/Nx2 1-channel or 1xN/Nx1 2-channel, or vectorPoint2f.affine仿射变换可以使用位姿矩阵进行初始化KCamera intrinsic matrix cameramatrixK.DInput vector of distortion coefficients (k1,k2,k3,k4).alphaThe skew coefficient.jacobianOptional 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.参考文献OpenCV的projectPoints函数用法_JIN_嫣熙的博客-CSDN博客_projectpointsOpencv学习12——cv::Rodrigues()函数_令狐少侠、的博客-CSDN博客_rodrigues函数OpenCV: Camera Calibration and 3D ReconstructionOpenCV: Fisheye camera modelundistortPoints opencv_cvml的博客-CSDN博客

相关新闻

Python GUI 编程库 tkinter

Python GUI 编程库 tkinter

tkinter (Tk interface) 是Python的标准GUl库,支持跨平台的GUl程序开发。tkinter适合小型的GUl程序编写,也特别适合初学者学习GUl编程。 Tkinter(即 tk interface,简称“Tk”)本质上是对 Tcl/Tk 软件包的 Python 接口…

2026/7/10 12:46:34 阅读更多 →
Streamlit 1.59.0 安装与虚拟环境配置:3种主流包管理器实战对比

Streamlit 1.59.0 安装与虚拟环境配置:3种主流包管理器实战对比

Streamlit 1.59.0 安装与虚拟环境配置:3种主流包管理器实战对比 在数据科学和机器学习领域,快速构建交互式Web应用的需求日益增长。Streamlit作为一款革命性的Python库,让开发者无需前端知识即可创建美观的数据应用。然而,不同包管…

2026/7/10 12:35:01 阅读更多 →
怎样自研一个Agent回放系统?

怎样自研一个Agent回放系统?

自研Agent回放系统的核心,是将Agent从“黑盒”转变为“确定性、可检查、可重放的状态机”。这意味着系统的设计需围绕状态的捕获、存储与恢复展开。以下是从实践中提炼的核心模块与实现要点: 🏗️ 核心架构:三大模块 一个完整的…

2026/7/10 12:35:01 阅读更多 →

最新新闻

(8-2)Bellman-Ford算法的局限性与改进

(8-2)Bellman-Ford算法的局限性与改进

Bellman-Ford算法的局限性与改进

2026/7/10 13:45:25 阅读更多 →
Obsidian表格插件终极指南:5个技巧实现笔记数据管理革命

Obsidian表格插件终极指南:5个技巧实现笔记数据管理革命

Obsidian表格插件终极指南:5个技巧实现笔记数据管理革命 【免费下载链接】obsidian-excel 项目地址: https://gitcode.com/gh_mirrors/ob/obsidian-excel 在知识管理领域,Obsidian表格插件正在彻底改变我们处理结构化数据的方式。这款强大的工具…

2026/7/10 13:43:24 阅读更多 →
Android Studio中文语言包终极指南:3分钟打造全中文开发环境

Android Studio中文语言包终极指南:3分钟打造全中文开发环境

Android Studio中文语言包终极指南:3分钟打造全中文开发环境 【免费下载链接】AndroidStudioChineseLanguagePack AndroidStudio中文插件(官方修改版本) 项目地址: https://gitcode.com/gh_mirrors/an/AndroidStudioChineseLanguagePack 你是否曾…

2026/7/10 13:41:20 阅读更多 →
SDXL概念流形技术:低计算成本实现生成图像精准操控

SDXL概念流形技术:低计算成本实现生成图像精准操控

这次我们来看一个关于SDXL模型的重要发现:概念流形(Concept Manifold)的识别与应用。这个发现的核心价值在于,它让我们能够用极低的计算成本实现对生成结果的精准操控,为SDXL模型的实用化打开了新的可能性。如果你正在…

2026/7/10 13:37:16 阅读更多 →
如何完全掌控微信聊天记录:3个简单步骤实现永久保存的终极指南

如何完全掌控微信聊天记录:3个简单步骤实现永久保存的终极指南

如何完全掌控微信聊天记录:3个简单步骤实现永久保存的终极指南 【免费下载链接】WeChatMsg 提取微信聊天记录,将其导出成HTML、Word、CSV文档永久保存,对聊天记录进行分析生成年度聊天报告 项目地址: https://gitcode.com/GitHub_Trending/…

2026/7/10 13:33:05 阅读更多 →
如何快速掌握LaTeX科学图表绘制:面向研究者的154个专业图表资源库

如何快速掌握LaTeX科学图表绘制:面向研究者的154个专业图表资源库

如何快速掌握LaTeX科学图表绘制:面向研究者的154个专业图表资源库 【免费下载链接】tikz Diagrams of concepts in physics/chemistry/ML 项目地址: https://gitcode.com/gh_mirrors/tikz/tikz 你是否曾经为学术论文或技术文档中的图表绘制而烦恼&#xff1f…

2026/7/10 13:33:05 阅读更多 →

日新闻

STM32与LTC1864高精度ADC的SPI通信实现

STM32与LTC1864高精度ADC的SPI通信实现

1. 项目背景与核心需求在工业控制和嵌入式系统开发中,模拟信号与数字系统的无缝集成一直是工程师面临的关键挑战。LTC1864作为一款16位高精度ADC转换器,配合STM32F101ZG这类主流微控制器,能够构建高性能的模拟信号采集系统。这种组合特别适合…

2026/7/10 0:03:07 阅读更多 →
猫抓插件:浏览器资源嗅探与视频下载的终极解决方案

猫抓插件:浏览器资源嗅探与视频下载的终极解决方案

猫抓插件:浏览器资源嗅探与视频下载的终极解决方案 【免费下载链接】cat-catch 猫抓 浏览器资源嗅探扩展 / cat-catch Browser Resource Sniffing Extension 项目地址: https://gitcode.com/GitHub_Trending/ca/cat-catch 还在为网页视频无法下载而烦恼吗&am…

2026/7/10 0:05:09 阅读更多 →
直流有刷电机驱动方案:TC78H653FTG与MKV46F256VLH16应用

直流有刷电机驱动方案:TC78H653FTG与MKV46F256VLH16应用

1. 直流有刷电机驱动方案概述在工业自动化和消费电子领域,直流有刷电机因其结构简单、控制方便、成本低廉等优势,仍然是许多应用场景的首选驱动方案。TC78H653FTG作为东芝推出的新一代H桥驱动器,与MKV46F256VLH16微控制器配合使用&#xff0c…

2026/7/10 0:05:09 阅读更多 →

周新闻

B站视频下载神器BiliTools:5分钟学会轻松保存任何B站内容

B站视频下载神器BiliTools:5分钟学会轻松保存任何B站内容

B站视频下载神器BiliTools:5分钟学会轻松保存任何B站内容 【免费下载链接】BiliTools A cross-platform bilibili toolbox. 跨平台哔哩哔哩工具箱,支持下载视频、番剧等等各类资源 项目地址: https://gitcode.com/GitHub_Trending/bilit/BiliTools …

2026/7/8 16:14:06 阅读更多 →
威胁模型全解析:从新手入门到实战应用,助你构建安全产品!

威胁模型全解析:从新手入门到实战应用,助你构建安全产品!

威胁模型的陌生现状在忙碌疲惫的一天里,参与了关于混合后量子密码学的讨论,应付端点攻击找茬的人,还参与留言板讨论后,发现“威胁模型”对多数人仍是陌生概念,且多被当作时髦用语。有趣的相关画作有一幅由 Embyr 创作的…

2026/7/9 13:46:46 阅读更多 →
渗透测试入门指南:从零基础到实战环境搭建

渗透测试入门指南:从零基础到实战环境搭建

1. 从“看热闹”到“入门”:我理解的渗透测试到底是什么?每次看到新闻里说某个大公司的数据被“黑”了,或者某个网站被攻击导致服务瘫痪,你是不是和我一样,心里会冒出两个念头:一是“这黑客真厉害”&#x…

2026/7/9 21:41:05 阅读更多 →

月新闻