Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calibration.flip()函数的原理 #23

Closed
kwong292521 opened this issue Jun 27, 2022 · 4 comments
Closed

Calibration.flip()函数的原理 #23

kwong292521 opened this issue Jun 27, 2022 · 4 comments

Comments

@kwong292521
Copy link

作者你好,在数据增强的水平翻转操作中,若图像进行了翻转,那么相机的相关标定信息会发生变化。在您的代码中体现在kitti.py中的calib.flip(img_size)这一操作,但是我不是很理解函数中为什么要构造cos_matrix这个矩阵以及用奇异值分解来求解相关系数,因此想向您请教一下该函数的相关数学原理出处,期待回复,非常感谢!!!

@SuperMHP
Copy link
Owner

  1. 这个的实现其实比较老土的,更新的实现直接对相机内参操作就可以。
  2. cos_matrix应该是命名不规范,其真正的含义是coefficient matrix(系数矩阵)
  3. 这里大概阐述原版的思路,细节推导写起来比较繁琐。大体上是这样,实际上你想求解p2d = A p3d。有一大堆point(一堆p2d和p3d的pair)求解A。然后这里并不能简单的直接算A,你可以看一下flip之前的calib matrix,会发现里面其实只有6个数值,很多的0,所以呢我就对这个公式”p2d = A p3d“进行了整理,写成这种:CX=0。这个X就是要算的6个数字,C就是系数矩阵,用p2d和p3d算出来的。然后对C做svd就好了。
  4. 以上方案在熟悉calib本身后其实并不需要,可以通过其他途径直接计算得到

@kwong292521
Copy link
Author

我使用了一个更简单的函数实现了这一功能(直接对内参进行操作,1.翻转后,0号相机与2号相机的相对位置刚好掉转,因此偏移量乘以-1;2.翻转时成像面也翻转了,因此相机的cu相对于图像中轴线也镜像翻转):

def flip_simple(self, img_size):
    img_w = img_size[0]
    _cu = img_w - self.cu
    self.cu = _cu
    self.P2[0, 2] = _cu
    self.tx *= -1
    self.P2[0, 3] *= -1

最终算出来的结果与您的原函数有很小的误差,我感觉应该也是对的?:

calib_1 = Calibration('./kitti/training/calib/000000.txt')
calib_2 = Calibration('./kitti/training/calib/000000.txt')
print("Raw P2:")
print(calib_1.P2)
calib_1.flip([1224, 370])
calib_2.flip_simple([1224, 370])
print("Raw Method:")
print(calib_1.P2)
print("Simple Method:")
print(calib_2.P2)

结果:
image

@SuperMHP
Copy link
Owner

SuperMHP commented Aug 8, 2022

正确的

@SuperMHP
Copy link
Owner

SuperMHP commented Oct 11, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants