⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rectifyepipolarline.asv

📁 这是我用Delphi和Matlab写的一个程序
💻 ASV
字号:
function [I0, I1, Precision] = RectifyEpipolarLine(lImg, rImg, lImgFPs, rImgFPs)
%  RECTIFICATION  Epipolar line rectification, return the rectified images
%  lImg: 左图像数据
%  rImg: 右图像数据
%  lImgFPs: 左图像的特征点。它是一个3×N的矩阵,矩阵的每一行为特征点的像素坐标(x, y, 1)'
%  rImgFPs: 右图像的特征点。它是一个3×N的矩阵,矩阵的每一行为特征点的像素坐标(x, y, 1)'
%  左右矩阵对应的一行为一对匹配点
%  I0: 校正后的左图像,I1: 校正后的右图像
%  Precision: 校正精度
%
%  刘然编写于2008年5月6日

%%  根据匹配点对计算基础矩阵F, e0: 左图像的极点(列向量),e1: 右图像的极点
[F, e0, e1] = GetFundamentalMatrix(lImgFPs, rImgFPs); 

%%  由F确定用于优化的七个参数(α、a、b、 eix、 eiy)的初始值。H0: 左图像的矩阵,H1: 右图像的矩阵,x0:初始向量
x0 = InitialParams(F, e0, e1);

%%  根据七个参数(α、a、b、 eix、 eiy)的初始值采用Levenberg-Marquardt算法进行优化,得到最终的H0和H1
%  优化函数的参数设定
options = optimset('MaxIter', 1e2, 'TolFun', 1e-20, 'LevenbergMarquardt', 'on', ...
  'MaxFunEvals', 1e6, 'TolX', 1e-25);

%  非线性优化函数lsqnonlin,要求参数Fun(user-defined function)返回一组值组成的向量(should
%  return a vector of values, [f(x1), f(x2), ..., f(xn)])。
%  定义全局变量,目的是将特征点传递给函数OptimalFun
global I0P
I0P = lImgFPs;
global I1P
I1P = rImgFPs;
[Result, resnorm, residual, exitflag, output] = lsqnonlin(@OptimalFun, x0, [], [], options);  
clear I0P;  %  清除全局变量
clear I1P;
%  由优化结果求出最终的H0和H1
[H0, H1] = GetHiFrom7Params(Result);

if Result(2) > 0 
    I0 = GetRectifiedImage(lImg, H0);  %  对图像lImg进行变换
    I1 = GetRectifiedImage(rImg, H1);  %  对图像rImg进行变换
    
else
    error('Parameter a <= 0, cannot continue, see the paper for details.');  %  每一句结束都打一个分号
end;

%%  计算校正精度
FPsRcd0 = H0 * lImgFPs;
FPsRcd1 = H1 * rImgFPs;
Precision = mean(abs( FPsRcd0(2,:) - FPsRcd1(2,:)));

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -