简体   繁体   English

为什么epiplolar geometry/sfm在python opencv中没有给出正确的值

[英]Why epiplolar geometry/sfm does not give proper values in python opencv

I tried to find rotation/translation between two images.我试图找到两个图像之间的旋转/平移。

For simplest case, I use two exact same images, and checked whether it gives 0 translations and rotations(identity matrix).对于最简单的情况,我使用两个完全相同的图像,并检查它是否给出了 0 个平移和旋转(身份矩阵)。

However it does not give the results that I expected.但是,它没有给出我预期的结果。 why???为什么???

在此处输入图片说明

ORB feature is used and ten matched features are used to find Essential matrix and R/t.使用 ORB 特征并使用十个匹配特征来查找基本矩阵和 R/t。 Result is (they are identical images):结果是(它们是相同的图像):

t =  [[ 0.57735027] [-0.57735027] [ 0.57735027]]
r = [[-0.33333333 -0.66666667  0.66666667]
     [-0.66666667 -0.33333333 -0.66666667]
     [ 0.66666667 -0.66666667 -0.33333333]]

What I expected is :我期望的是:

t = [[0, 0, 0]]
r = [[1, 0, 0], [0, 1, 0], [0, 0, 0]]

Why it does not give strange results?为什么它不会给出奇怪的结果?

    orb = cv2.ORB_create()
    img1 = self.img1
    img2 = self.img2

    gray2 = cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY)
    gray1 = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)

    kpts1, descs1 = orb.detectAndCompute(gray1, None)
    kpts2, descs2 = orb.detectAndCompute(gray2, None)

    bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)
    matches = bf.match(descs1, descs2)
    dmatches = sorted(matches, key=lambda x: x.distance)

    src_pts = np.float32([kpts1[m.queryIdx].pt for m in dmatches]).reshape(-1, 1, 2)
    src_pts = src_pts[0:10]
    dst_pts = np.float32([kpts2[m.trainIdx].pt for m in dmatches]).reshape(-1, 1, 2)
    dst_pts = dst_pts[0:10]

    K = np.array([[842.102288, 0., 263.697271],
                  [0., 833.300569, 536.024168],
                  [0., 0., 1.]])

    E, mask2 = cv2.findEssentialMat(src_pts, dst_pts, K, cv2.RANSAC, 0.999, 1.0);
    points, R, t, mask = cv2.recoverPose(E, src_pts, dst_pts)

test image (image1=image2=img)测试图片 (image1=image2=img) 在此处输入图片说明

sometimes we need to test to find the problem, so it will be very useful if you put the link to the image.有时候我们需要通过测试来发现问题,所以如果你把链接放到图片上会非常有用。

However, there are a few things you should know:但是,您应该了解以下几点:

  • By default on OpenCV, the maximum number of keypoints to be detected using the ORB detector is equal to 500 keypoints默认情况下,在 OpenCV 上,使用 ORB 检测器检测的关键点的最大数量等于 500 个关键点
  • By calculating the essential matrix , you get inliers as well as outliers which are represented by a mask, but according to your source code, you don't take it into consideration, which affects the result of recoverpose通过计算基本矩阵,您可以获得由掩码表示的内点和离群值,但是根据您的源代码,您没有考虑它,这会影响recoverpose的结果
  • Recoverpose also needs the camera matrix Recoverpose还需要相机矩阵

So for a first step, I ask you to test this code, while waiting for the publication of your image因此,第一步,我请您测试此代码,同时等待您的图像发布

    orb = cv2.ORB_create(nfeatures = 2000)
    img1 = self.img1
    img2 = self.img2

    gray2 = cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY)
    gray1 = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)

    kpts1, descs1 = orb.detectAndCompute(gray1, None)
    kpts2, descs2 = orb.detectAndCompute(gray2, None)

    bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)
    matches = bf.match(descs1, descs2)
    dmatches = sorted(matches, key=lambda x: x.distance)

    src_pts = np.float32([kpts1[m.queryIdx].pt for m in dmatches]).reshape(-1, 1, 2)
    dst_pts = np.float32([kpts2[m.trainIdx].pt for m in dmatches]).reshape(-1, 1, 2)

    K = np.array([[842.102288, 0., 263.697271],
                  [0., 833.300569, 536.024168],
                  [0., 0., 1.]])

    E, inliers_mask_E = cv2.findEssentialMat(src_pts, dst_pts, K method = cv2.RANSAC, prob = 0.999, threshold = 1.0);
    points, R, t, inliers_mask_RP = cv2.recoverPose(E, src_pts, dst_pts, cameraMatrix = K, mask = inliers_mask_E)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么从 OpenCV python 示例中读取图像会给出错误,而在 C++ 中却没有给出错误? - Why does reading an image from OpenCV python samples giving error where as it does not give error in c++? 为什么在指定 Dsize 与 fx/fy 时 OpenCV Resize 会给出不同的像素值? - Why Does OpenCV Resize Give Different Pixel Values When Specifying Dsize vs. fx/fy? 为什么python“(hash).values()”会给出“(hash).keys()没有给出的错误? - Why does python “(hash).values()” give an error that "(hash).keys() doesn't give? 为什么python不给我关闭openCV窗口的选项? - why doesn't python give me the option to close openCV window? 为什么Python中的线性化会产生这种奇怪的结果? - Why does linearization in Python give this bizarre result? 为什么这个脚本给我乱码? (蟒蛇) - Why does this script give me gibberish? (python) 为什么len(“”。split(“”))给出1? 蟒蛇 - Why does len(“”.split(“ ”)) give 1? python 为什么网络摄像头没有出现在 python-opencv 中 - Why webcam does not appear in python-opencv 为什么在不同的操作系统和版本中打印这些值会给出不同的值? - Why does printing these values give different values in different OS and versions? 为什么 sys.getrefcount 会给出巨大的值? - Why does sys.getrefcount give huge values?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM