有效计算像素到其对应对极线的距离

我正在尝试计算立体相机设置中两个相应像素到它们各自的对极线的距离。我为此目的实现的代码如下:

#include <iostream>
#include <vector>
#include <opencv2/calib3d/calib3d.hpp>

float calculateDistanceToEpiLinesum(const cv::Mat2f& left_candidate,const cv::Mat2f& right_candidate,const cv::Matx33f& fundamental_mat) {

  // Calculate epipolar lines
  cv::Mat epiLineRight=cv::Mat(1,3,CV_32FC1);
  cv::Mat epiLineLeft=cv::Mat(1,CV_32FC1);
  cv::computeCorrespondEpilines(left_candidate,2,fundamental_mat,epiLineRight);
  cv::computeCorrespondEpilines(right_candidate,1,epiLineLeft);

  // Calculate distances of the image points to their corresponding epipolar line
  float distance_left_im=std::abs(epiLineLeft.at<float>(0)*left_candidate[0][0][0]+
                                   epiLineLeft.at<float>(1)*left_candidate[0][0][1]+
                                   epiLineLeft.at<float>(2))/
      std::sqrt(std::pow(epiLineLeft.at<float>(0),2.f)+std::pow(epiLineLeft.at<float>(1),2.f));

  float distance_right_im=std::abs(epiLineRight.at<float>(0)*right_candidate[0][0][0]+
                                   epiLineRight.at<float>(1)*right_candidate[0][0][1]+
                                   epiLineRight.at<float>(2))/
      std::sqrt(std::pow(epiLineRight.at<float>(0),2.f)+std::pow(epiLineRight.at<float>(1),2.f));

  return distance_left_im+distance_right_im;
}

int main()
{
  cv::Matx33f fundamental_mat=cv::Matx33f{-0.000000234008931f,-0.000013193232976f,0.010025275471910f,-0.000017896532640f,0.000009948056751f,0.414125924093639f,0.006296743991557f,-0.411007947095269f,-4.695511356888332f};

  cv::Vec2f left_candidate_vec=cv::Vec2f(135.,289.);
  cv::Vec2f right_candidate_vec=cv::Vec2f(205.,311.);
  cv::Mat2f left_candidate=cv::Mat(left_candidate_vec);
  cv::Mat2f right_candidate=cv::Mat(right_candidate_vec);

  float distance_sum=calculateDistanceToEpiLinesum(left_candidate,right_candidate,fundamental_mat);

  std::cout<<"The sum of the distances equals "<<distance_sum<<" pixels\n";

  return 0;
}

我面临的问题是,我将不得不每秒执行数千次此操作。我知道cv::computeCorrespondEpilines的第一个输入可以是像素矢量,它可以采用更矢量化的方法,并且可能会加快速度。问题是,我不能使用此功能,因为我不使用常规相机,但是使用event-based sensors,因此我将异步接收像素(而不是接收帧)。
现在,我想了解以下内容:

  1. calculateDistanceToEpiLinesum中是否存在任何主要缺陷? 影响功能性能的方式不好吗?不在这里使用OpenCV函数而是自己实现computeCorrespondEpilines也许是个好主意?
  2. 我想过要计算对极线“离线” 节省处理时间。问题是,我不知道该怎么办 有效地计算并保护对极线。我想过 计算每个图像的每个像素的对极线,并 根据{{​​1}}将行参数存储在三元组中, 但是假设每个摄像机的分辨率为480x360, 我有两个很大的480x360x3矩阵。这样做可行吗 还是这样,还是有更好的方法?
zhongyi9927 回答:有效计算像素到其对应对极线的距离

如果不知道您的计算约束是什么,就无法回答时间性能的问题,因此以下是一个非常粗略的估计。

在底部,计算候选匹配像素对的一个点与其关联的对极线之间的距离大约需要花费

  • 一个矩阵乘法= 9乘,6加= 15触发器
  • 归一化= 2个多,1个加法,1个平方根=〜10个触发器
  • 线积为3乘2加= 5翻牌的点积
  • Division =〜4 flops

这对大约有70次翻牌。

以秒为单位的所有含义至少取决于您的处理器时钟周期。 Skylake IA64可以每周期执行16个DP矢量化触发器,因此将其称为5个周期。在3 GHz时,所需时间不到2 ns。以此为基础,我们可以称其为10 ns。

您说您必须每秒执行“千次”此计算。以每对10ns的速度,您每秒可以完成 1亿

鉴于上述情况,您确定此特定操作将成为瓶颈,而不是例如摄像机的I / O(包括图像解码)吗?

忠告:学习使用良好的微基准测试框架来获取硬件的实际性能指标。我推荐旧的Google Benchmark
本文链接:https://www.f2er.com/3081769.html

大家都在问