当前位置: 首页 > news >正文

OpenCV相机标定与3D重建(28)估计两个三维点集之间的最优平移变换函数estimateTranslation3D()的使用

  • 操作系统:ubuntu22.04
  • OpenCV版本:OpenCV4.9
  • IDE:Visual Studio Code
  • 编程语言:C++11

算法描述

计算两个3D点集之间的最优平移。

它计算
[ x y z ] = [ X Y Z ] + [ b 1 b 2 b 3 ] \begin{bmatrix} x\\ y\\ z\\ \end{bmatrix} = \begin{bmatrix} X\\ Y\\ Z\\ \end{bmatrix} + \begin{bmatrix} b_1\\ b_2\\ b_3\\ \end{bmatrix} xyz = XYZ + b1b2b3

cv::estimateTranslation3D 是 OpenCV 库中的一个函数,用于估计两个三维点集之间的最优平移变换。此函数通常用于3D图像配准、物体识别和追踪等领域。它通过最小化源点集与目标点集之间的几何误差来估计平移向量,并且可以选择使用鲁棒方法(如RANSAC)来处理异常值(outliers)。

函数原型

int cv::estimateTranslation3D	
(InputArray 	src,InputArray 	dst,OutputArray 	out,OutputArray 	inliers,double 	ransacThreshold = 3,double 	confidence = 0.99 
)		

参数

  • 参数src 第一个输入的3D点集,包含 (X, Y, Z)。

  • 参数dst 第二个输入的3D点集,包含 (x, y, z)。

  • 参数out 输出的3D平移向量 3×1,形式如下:
    [ b 1 b 2 b 3 ] \begin{bmatrix} b_1 \\ b_2 \\ b_3 \\ \end{bmatrix} b1b2b3

  • 参数inliers 输出向量,指示哪些点是内点(1-内点,0-外点)。

  • 参数ransacThreshold 在RANSAC算法中,考虑一个点为内点的最大重投影误差。

  • 参数confidence 对估计变换的置信水平,在0和1之间。通常0.95到0.99之间的值就足够了。过于接近1的值可能会显著减慢估计过程。低于0.8-0.9的值可能导致变换估计不准确。

该函数使用RANSAC算法估计两个3D点集之间的最优3D平移。

代码示例


#include <iostream>
#include <opencv2/opencv.hpp>
#include <vector>using namespace cv;
using namespace std;int main()
{// 定义两组对应的3D点 (X, Y, Z) - 源点集和目标点集vector< Point3f > src = { Point3f( 0, 0, 0 ), Point3f( 1, 0, 0 ), Point3f( 0, 1, 0 ), Point3f( 0, 0, 1 ) };vector< Point3f > dst = { Point3f( 1, 1, 1 ), Point3f( 2, 1, 1 ), Point3f( 1, 2, 1 ), Point3f( 1, 1, 2 ) };// 定义一个 Mat 来接收输出的平移向量矩阵Mat translationVector;// 定义一个 Mat 来接收内点信息vector< uchar > inliers;// 调用 estimateTranslation3D 函数int inlierCount = estimateTranslation3D( src, dst, translationVector, inliers );if ( !translationVector.empty() ){cout << "Estimated Translation Vector:\n" << translationVector << endl;cout << "Number of inliers: " << inlierCount << endl;// 打印哪些点被认为是内点for ( size_t i = 0; i < inliers.size(); ++i ){if ( inliers[ i ] ){cout << "Point pair (" << src[ i ] << ", " << dst[ i ] << ") is an inlier.\n";}else{cout << "Point pair (" << src[ i ] << ", " << dst[ i ] << ") is an outlier.\n";}}}else{cout << "Failed to estimate translation." << endl;}return 0;
}

运行结果

Estimated Translation Vector:
[1, 1, 1]
Number of inliers: 1
Point pair ([0, 0, 0], [1, 1, 1]) is an inlier.
Point pair ([1, 0, 0], [2, 1, 1]) is an inlier.
Point pair ([0, 1, 0], [1, 2, 1]) is an inlier.
Point pair ([0, 0, 1], [1, 1, 2]) is an inlier.
http://www.lryc.cn/news/508386.html

相关文章:

  • UE5仿漫威争锋灵蝶冲刺技能
  • CSS盒子模型(溢出隐藏,块级元素和行级元素的居中对齐,元素样式重置)
  • 语音增强的损失函数选择
  • 【python自动化六】UI自动化基础-selenium的使用
  • 【习题答案】让您的应用拥有领先的位置服务能力
  • java中list和map区别
  • java后端传时间戳给前端的三种方式
  • 【机器学习与数据挖掘实战】案例06:基于Apriori算法的餐饮企业菜品关联分析
  • oracle: create new database
  • 混合开发环境---使用编程AI辅助开发Qt
  • Sigrity SystemSI仿真分析教程文件路径
  • 【YashanDB知识库】Oracle pipelined函数在YashanDB中的改写
  • 【开发实战】QT5+ 工业相机 + OpenCV工作流集成演示
  • 各种电机原理介绍
  • 深入了解 React:从入门到高级应用
  • Cglib代理简单案例
  • FreeMarker语法
  • DP动态规划(装箱问题)
  • 内网IP段介绍与汇总
  • 三、ubuntu18.04安装docker
  • 数据库与表空间
  • 【CSS in Depth 2 精译_091】15.4:让 CSS 高度值过渡到自动高度 + 15.5:自定义属性的过渡设置(全新)+ 15.6:本章小结
  • Oracle中间件 SOA之 OSB 12C服务器环境搭建
  • Java设计模式 —— 【结构型模式】外观模式详解
  • 线性表实验
  • 003无重复字符的最长子串
  • 记录--uniapp 安卓端实现录音功能,保存为amr/mp3文件
  • 前端生成docx文档、excel表格、图片、pdf文件
  • c++---------流类
  • 3、基本复用原理和复用单元