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)
相关推荐
寒水馨1 小时前
macOS下载、安装godot-4.7.1-stable(附安装包Godot_v4.7.1-stable_macos.universal.zip)
macos·3d·游戏引擎·godot·跨平台·游戏开发·2d
小保CPP1 天前
OpenCV C++基于AI模型的场景文本识别(OCR)
c++·人工智能·opencv·计算机视觉·ocr
3D小将1 天前
3D格式转换之Rhino(Rhinoceros)转 CATIA 标准化转换技术
3d·solidworks模型·ug模型·rhino模型·catia模型
爱吃程序猿的喵2 天前
LingBot-Map 复现与原理剖析:基于 Geometric Context Transformer 的流式 3D 重建
人工智能·python·深度学习·计算机视觉·3d·transformer
xcLeigh2 天前
Unity基础:创建你的第一个游戏物体——Cube、Sphere与基本3D物体
游戏·3d·unity·教程
程序员正茂3 天前
Android studio中初步使用OpenCV库
android·opencv
蓝速科技3 天前
蓝速科技 3D 全息舱展览馆落地实测:降噪算力与成像质量深度评测
人工智能·科技·3d
fengbingchun3 天前
3D领域常用术语总结
3d
小保CPP3 天前
OpenCV C++将多张图像合并为webp动图
c++·人工智能·opencv·计算机视觉