我正在尝试通过使用
基本矩阵,以及在 Wikipedia 上给出的算法.为了
我需要找到基本矩阵。我在用
OpenCV::findFundamentalMat
为此。
两个意想不到的行为:
- 使用不同的拟合算法会产生不同的结果,
特别是
FM_8POINT
是不同的。 - 给定一组点对 (y, x),yFx = 0 不满足并且 总是大于 0。
我是不是没看懂?我的例子是错误的,还是什么 怎么回事?谁能推荐一个更好的测试示例?
下面是一个最小的例子。创建 12 个人工点,移动每个
这些点向右 10 个像素,从中找到基本矩阵
这两组点和打印yFx
对于每个点。
例子:
int main(int argc, const char* argv[])
{
// Create two sets of points. Points in pts2 are moved 10pixel to the right of the points in pts1.
std::vector<cv::Point2f> pts1, pts2;
for(double y = 0; y < 460; y+=150)
{
for(double x= 0; x < 320; x += 150)
{
pts1.push_back(cv::Point2f(x, y));
pts2.push_back(cv::Point2f(x+10.0, y));
}
}
cv::Mat F = cv::findFundamentalMat(pts1, pts2);
for(int i = 0; i < pts1.size(); i++)
{
// Creating p1, p2, the two points. Please let me know if this can be done in fewer lines.
cv::Mat p1(3,1, CV_64FC1), p2(3,1, CV_64FC1);
p1.at<double>(0) = pts1.at(i).x;
p1.at<double>(1) = pts1.at(i).y;
p1.at<double>(2) = 1.0;
p2.at<double>(0) = pts2.at(i).x;
p2.at<double>(1) = pts2.at(i).y;
p2.at<double>(2) = 1.0;
// Print yFx for each pair of points. This should be 0 for all.
cout << p1.t() * F * p2 << endl;
}
}
对于 FM_RANSAC
我明白了
[1.999], [2], [2], [1.599], [1.599], [1.599], [1.198], [1.198], [1.198], [0.798], [0.798], [0.798]
对于 FM_8POINT
基本矩阵是 zeros(3,3)
因此 yFx
是0
对于所有 y
, x
.
我只找到:T and R estimation from essential matrix但这并没有多大帮助。
编辑:yFx
是错误的方式(p1
/p2
在 cout 行中切换)。这个例子也不起作用,因为所有的点都在一个平面上。
最佳答案
我相信基本矩阵可以求解方程 p2.t() * F * p1 = 0
,即您的代码中的 p1 和 p2 颠倒了。至于为什么 8 点算法返回零矩阵,我不知道,抱歉。
编辑:好的,我相信我记得为什么 8 点算法在这里产生了一个糟糕的结果。两组点之间的运动是纯平移,没有旋转,即它只有三个自由度。基本矩阵有7个自由度,所以无法估计;这称为退化情况。参见 this paper进一步描述基本/基本矩阵估计中的退化情况。
也可能是人为移动像素坐标得到的两个视点之间没有刚性变换,从而没有满足要求的基础矩阵。更好的测试用例可能是使用具有已知扭曲矩阵的函数,例如 cv::warpPerspective。
关于image-processing - FindFundamentalMatrix 找不到基本矩阵,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6832983/