OpenCV 位姿与投影变换

发布时间:2026/10/28 20:24:34

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博客
延伸阅读

更多相关文章

2026/10/24 8:31:34

vue动态改变el-table表格列

方法1 <template><div class"mainBox"><div class"optshowBox"><el-popover placement"bottom" trigger-"click" width"200" popper-class"popperStyle"><template #reference><…

2026/10/25 18:04:20

计算机毕业设计之容春茶叶商城系统设计与实现

本系统为用户而设计制作容春茶叶商城系统&#xff0c;旨在实现容春茶叶商城系统智能化、现代化管理。本容春茶叶商城系统自动化系统的开发和研制的最终目的是将容春茶叶商城系统的运作模式从手工记录数据转变为网络信息查询管理&#xff0c;从而为现代管理人员的使用提供更多的…

2026/10/28 20:24:15

OpenClaw多场景部署方案与Node.js版本适配指南

1. OpenClaw部署方案全景概览OpenClaw作为阿里云生态中的新兴工具链组件&#xff0c;近期在开发者社区引发了广泛关注。根据实际部署场景的差异&#xff0c;我将五种主流部署方案归纳为以下技术矩阵&#xff1a;方案类型适用场景核心优势典型硬件要求轻量应用服务器快速验证/PO…

2026/10/28 20:24:15

SC-VAE训练损失函数解析与调参技巧

1. Trellis工作流中的SC-VAE训练损失函数解析在3D-AICG领域&#xff0c;Trellis工作流作为新一代生成式AI框架&#xff0c;其核心组件SC-VAE&#xff08;Structured Convolutional Variational Autoencoder&#xff09;的训练过程直接决定了模型生成质量。今天我们就来拆解这个…

2026/10/28 20:24:15

Jotai原子状态管理:React轻量级状态解决方案

1. Jotai原子状态管理库概述Jotai是一个轻量级的React状态管理库&#xff0c;它采用原子(atom)的概念来构建应用状态。与Redux等传统状态管理方案不同&#xff0c;Jotai的核心设计理念是将状态分解为最小的原子单位&#xff0c;通过组合这些原子来构建复杂的状态逻辑。我第一次…

2026/10/28 20:24:15

VLA模型如何理解日常指令:以‘我渴了‘为例

1. VLA模型如何理解“我渴了”这类日常指令&#xff1f;当我对家里的智能音箱说"我渴了"时&#xff0c;它居然回应"需要帮您点奶茶还是矿泉水&#xff1f;"——这个看似简单的交互背后&#xff0c;是视觉语言动作模型&#xff08;Vision-Language-Action M…

2026/10/28 20:24:15

论文分类码不是标签:定长字符串中的层级编码与检索

简介&#xff1a;这份PDF文档是PACS 2008版《Physics and Astronomy Classification Scheme》分类索引&#xff0c;面向物理学、天文学及交叉学科的研究生、教师和论文投稿作者&#xff0c;帮助在投稿时准确选择主题分类代码&#xff0c;满足部分期刊要求使用PACS标注文章领域的…

2026/10/28 20:19:14

AI图片生成工具的商业价值与技术解析

1. 项目概述&#xff1a;AI图片生成工具的迭代与市场变革最近注意到一个有趣的现象&#xff1a;当某款知名AI视频工具&#xff08;我们暂且称为Sora 2&#xff09;逐渐淡出创作者视野时&#xff0c;一批新兴的图片生成工具正在悄然崛起。其中橘子AI的图片模型表现尤为突出&…

2026/10/28 14:42:12

全国计算机二级C语言真题PDF高效刷题指南

简介&#xff1a;这份PDF是全国计算机二级C语言考试的试题与答案解析&#xff0c;专为备考二级C语言的考生准备。内容涵盖C语言特点与设计理念、程序基本组成单位、main函数执行流程、函数嵌套调用规则、标识符命名规范、整型实型字符型数据类型、八进制十六进制数合法形式、运…

2026/10/28 15:28:56

requests+BeautifulSoup:爬虫抓取h1标题的入门实战指南

简介&#xff1a;一份以实战为导向的Python爬虫入门资源&#xff0c;面向具备基本编程基础、希望快速掌握网络数据抓取的初学者&#xff0c;可解决从零编写简单爬虫的常见困惑。实例以requests库发送HTTP请求、BeautifulSoup解析HTML文档&#xff0c;完整演示从网页中提取 标题…

2026/10/28 3:32:29

递推最小二乘参数辨识MATLAB编程:二阶系统与渐消记忆实现

简介&#xff1a;这是一篇面向控制系统、信号处理与机器学习等领域学习者的最小二乘参数辨识程序说明文档。资源共包含一个docx格式文档&#xff0c;压缩包大小七十八KB&#xff0c;内容围绕递推最小二乘算法和渐消记忆最小二乘算法展开&#xff1a;先构造一个极点位于单位圆内…

2026/10/28 0:02:13

Python股票自动交易系统源码解析:从行情获取到风控的完整链路

简介&#xff1a;这份资源是面向高校计算机、金融相关专业毕业设计场景的完整项目源码包&#xff0c;主题为基于Python的股票自动交易系统&#xff0c;适合需要完成毕设选题、课程设计或自学金融量化交易开发的学生与开发者参考。压缩包共收录687个文件&#xff0c;整体约14.93…

2026/10/28 0:02:13

视酷酷信IM源码部署指南:Java 17+MySQL 8.0.33实战配置

简介&#xff1a;这是一套2024年亲测可部署的视酷酷信IM即时通讯系统源码&#xff0c;面向具备Java、OC、C#及Vue开发能力的技术人员&#xff0c;解决私有化即时通讯平台快速搭建与二次定制需求&#xff0c;尤其适用于需集成商城、保障数据主权的中小型企业或独立开发者。资源共…

2026/10/28 0:02:13

Python爬取百度迁徙数据:接口解析、批量采集与避坑指南

简介&#xff1a;这份资源是一个用Python爬取百度迁徙数据的脚本压缩包&#xff0c;面向具备Python基础、希望入门网络爬虫与数据解析的开发者&#xff0c;解决按日期获取全国热门城市人口迁徙数据的问题。包内共1个文件&#xff0c;为单个py脚本&#xff0c;压缩包约1KB&#…

还想了解更多?直接咨询顾问

免费诊断 + 免费方案 + 透明报价。

全国咨询热线400-8866-253
免费获取方案
☎咨询二维码 ☎ ↑