OpenCV相机标定与3D重建(18)根据基础矩阵(Fundamental Matrix)校正两组匹配点函数correctMatches()的使用

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

算法描述

优化对应点的坐标。

cv::correctMatches 是 OpenCV 库中的一个函数,用于根据基础矩阵(Fundamental Matrix)校正两组匹配点。该函数通过最小化重投影误差来优化匹配点的位置,从而提高特征点匹配的准确性。

函数原型

cpp 复制代码
void cv::correctMatches
(
	InputArray 	F,
	InputArray 	points1,
	InputArray 	points2,
	OutputArray 	newPoints1,
	OutputArray 	newPoints2 
)		

参数

  • 参数F:3x3 的基础矩阵。
  • 参数points1:包含第一组点的 1xN 数组。
  • 参数points2:包含第二组点的 1xN 数组。
  • 参数newPoints1:优化后的第一组点。
  • 参数newPoints2:优化后的第二组点。

该函数实现了最优三角化方法(详见《Multiple View Geometry》115)。对于每个给定的点对应关系points1i <-> points2i 和一个基础矩阵 F,它计算校正后的对应关系 newPoints1i <-> newPoints2i,以最小化几何误差 d ( p o i n t s 1 i , n e w P o i n t s 1 i ) 2 + d ( p o i n t s 2 i , n e w P o i n t s 2 i ) 2 d(points1i, newPoints1i)^2 + d(points2i,newPoints2i)^2 d(points1i,newPoints1i)2+d(points2i,newPoints2i)2(其中 d ( a , b ) d(a,b) d(a,b) 是点 a 和点 b 之间的几何距离),同时满足极线约束 n e w P o i n t s 2 T ⋅ F ⋅ n e w P o i n t s 1 = 0 newPoints2^T \cdot F \cdot newPoints1 = 0 newPoints2T⋅F⋅newPoints1=0

使用场景

  • 立体视觉:在双目或多目视觉系统中,用于提高特征点匹配的精度。
  • 结构光扫描:在校正三维重建过程中使用的匹配点时非常有用。
  • 运动估计:在基于特征点的运动估计任务中,可以提高估计的准确性。

代码示例

cpp 复制代码
#include <iostream>
#include <opencv2/opencv.hpp>

int main()
{
    // 假设我们已经得到了基础矩阵 F 和两组匹配点 points1 和 points2
    cv::Mat F = ( cv::Mat_< double >( 3, 3 ) << 0.998, -0.062, 0.007, 0.062, 0.998, -0.05, 0.007, 0.05, 1.0 );

    // 定义一些匹配点
    std::vector< cv::Point2f > points1 = { cv::Point2f( 100, 150 ), cv::Point2f( 200, 250 ) };
    std::vector< cv::Point2f > points2 = { cv::Point2f( 105, 155 ), cv::Point2f( 205, 255 ) };

    // 创建输出容器
    std::vector< cv::Point2f > newPoints1;
    std::vector< cv::Point2f > newPoints2;

    // 优化对应点的坐标
    cv::correctMatches( F, points1, points2, newPoints1, newPoints2 );

    // 打印结果
    for ( size_t i = 0; i < newPoints1.size(); ++i )
    {
        std::cout << "Original Points: (" << points1[ i ].x << ", " << points1[ i ].y << ") -> (" << points2[ i ].x << ", " << points2[ i ].y << ")\n";
        std::cout << "Optimized Points: (" << newPoints1[ i ].x << ", " << newPoints1[ i ].y << ") -> (" << newPoints2[ i ].x << ", " << newPoints2[ i ].y << ")\n";
    }

    return 0;
}

运行结果

bash 复制代码
Original Points: (100, 150) -> (105, 155)
Optimized Points: (-39.0672, 88.7914) -> (146.107, 75.3975)
Original Points: (200, 250) -> (205, 255)
Optimized Points: (-46.7855, 188.856) -> (259.562, 81.6427)
相关推荐
Java患者·1 分钟前
《Python 人脸识别入门实践:从人脸检测到人脸比对完整实现》
开发语言·python·opencv·目标检测·计算机视觉·目标跟踪·视觉检测
丨白色风车丨3 小时前
OpenCV 实战入门:轮廓检测、模板匹配与命令行参数解析
人工智能·opencv·计算机视觉
趋之6 小时前
Mars3D 三维可视化开发入门实战教程
3d
探物 AI6 小时前
零基础入门3D点云深度学习:从PointNet开始,理解3D数据处理
人工智能·深度学习·3d
Jerryhut7 小时前
opencv对齐算法及其应用
人工智能·opencv·算法
码来的小朋友7 小时前
[Python] 制作小游戏创意之3D魔方
python·3d·pygame
盼小辉丶8 小时前
OpenCV-Python实战(28)——OpenCV计算摄影从HDR图像融合到全景拼接
python·opencv·计算机视觉
pythonpioneer18 小时前
PyTorch3D:基于 PyTorch 的高效 3D 深度学习工具库
pytorch·深度学习·其他·3d
大江东去浪淘尽千古风流人物19 小时前
【PromptStereo】零样本立体匹配新范式:用结构与运动Prompt驱动迭代优化(CVPR 2026)
深度学习·3d·slam·视觉定位·dust3r·3d重建·mast3r
智海深蓝21 小时前
海上平行战场:态势模拟三维可视化平台
3d·ue5