OpenCV的imread与getFundamentalMatrix

0 投票
1 回答
1681 浏览
提问于 2025-04-17 22:04

我无法让这个工作:

img1 = cv::imread('glassL.jpg')
img2 = cv::imread('glassR.jpg')

img1g = cv::Mat.new
cv::cvtColor(img1, img1g, CV_BGR2GRAY);
img2g = cv::Mat.new
cv::cvtColor(img2, img2g, CV_BGR2GRAY);

F = cv::findFundamentalMat(img1g, img2g, cv::FM_RANSAC, 0.1, 0.99)

它抛出了这个错误:

OpenCV Error: Assertion failed (npoints >= 0 && points2.checkVector(2) == npoints && points1.type() == points2.type()) in findFundamentalMat, file /tmp/opencv-XbIS/opencv-2.4.8.2/modules/calib3d/src/fundam.cpp, line 1103
/usr/local/var/rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/ropencv-0.0.15/lib/ropencv/ropencv_types.rb:10509:in `find_fundamental_mat': /tmp/opencv-XbIS/opencv-2.4.8.2/modules/calib3d/src/fundam.cpp:1103: error: (-215) npoints >= 0 && points2.checkVector(2) == npoints && points1.type() == points2.type() in function findFundamentalMat (RuntimeError)

我正在使用 ropencv(Ruby + FFI),但我也尝试了 Python 的 cv2,结果得到了完全相同的错误。我找不到任何相关的文档,感觉很迷茫。checkVector(2) 在处理灰度图像和彩色图像时都返回 -1,我不知道该如何转换它们才能与 findFundamentalMat 一起使用。请帮帮我。

1 个回答

0

你直接把图片传给计算基础矩阵的函数,这样做是不对的。在文档里说:

  • points1 – 第一个图片中的N个点的数组。点的坐标应该是浮点数(单精度或双精度)。
  • points2 – 第二个图片中与points1大小和格式相同的点的数组。

所以,你不能简单地把图片放进去。这里有一个完整的例子,使用OpenCV的链接。另外,这里还有一个很好的逐步解释链接,使用matlab,让你明白你要用哪些点(比如哈里斯角点)。

撰写回答