OpenCV Camera calibration from a set of 3d and corresponding 2d points

问题描述 投票:0回答:0

我是新来的,我在校准方面遇到了一些麻烦。

我将在 Unity3D 中合成帧作为数据集(如 MultiviewX )以进行进一步的 CNN 训练。 第一步,我需要校准相机以获得相机的内部和外部。是的,有一些数学方法可以得到内在函数和外在函数。但是,如果我能从 OpenCV 中得到结果,那就更好了。

为了完成校准,我设置了很多点的场景(如下图)。我可以获得生成的绿点的 3D 世界位置(通过 gameobject.transform.position)和 2D 屏幕位置(通过 camera.worldToScreen())。

这里是数据:https://github.com/TsingLoo/MultiviewX_FYP/tree/master/cali

我认为通过使用相应的 3D-2D 点对

size = (1920,1080)
points_2d = np.loadtxt(f'calib/Camera{cam + 1}.txt')
points_3d = np.loadtxt(f'calib/Camera{cam + 1}_3D.txt')

points_2d = np.concatenate(points_2d, axis=0).reshape([1, -1, 2]).astype('float32')
points_3d = np.concatenate(points_3d, axis=0).reshape([1, -1, 3]).astype('float32')

cameraMatrix = cv2.initCameraMatrix2D(points_3d, points_2d, size, 1)

retval, cameraMatrix, distCoeffs, rvecs, tvecs = \
    cv2.calibrateCamera(points_3d, points_2d, size, cameraMatrix, None,flags = cv2.CALIB_USE_INTRINSIC_GUESS)

可以获得正确的校准(fx = fy = 935f)。但是,结果差异很大。

我想得到正确的校准(内在和外在)结果是这样的:https://github.com/hou-yz/MultiviewX/tree/master/calibrations

我注意到 cv2.calibrateCamera 的 OpenCV 文档提到 Z 值应该为零。我试过了,但仍然没有得到正确的校准。

unity3d opencv camera-calibration
© www.soinside.com 2019 - 2024. All rights reserved.