在图像上绘制相机轴

时间:2018-08-21 10:11:21

标签: python opencv camera-calibration

我有一些图像,我想在它们上绘制相机轴(姿势)。 对于每个图像,我都知道相机旋转矩阵,平移矢量和相机内在矩阵。

I took this tutorial as an example 但是我没有使用opencv和棋盘来校准相机,而是从其他软件获得了相机校准。 使用projectPoints会给我带来奇怪的结果。

这或多或少是我要做的

# Initialize axis
axis = np.float32([[1,0,0], [0,1,0], [0,0,-1]]).reshape(-1,3)

# Initialize camera matrix, shared between all images
C = np.float32([[2696.178, 0, 1633.029], [0, 2696.178, 910.477], [0, 0, 1]])

for img in os.listdir(folder):

    # ... get R and T from the calibration file... 

    rvec, _ = cv2.Rodrigues(R)

    imgpts, jac = cv2.projectPoints(axis, rvec, T, C, np.float32([0, 0, 0, 0]))

    # ... draw axis on image ...    

如果我从图像中心绘制轴,则它们似乎在不同图像之间处于完全随机的位置

enter image description here

我在这里发布上面图片中使用的数据

# Camera intrinsics matrix
# [[fx 0  cx]
#  [0  fy cy]
#  [0  0  1]]
C = [[2.696178e+03 0.000000e+00 1.633029e+03]
 [0.000000e+00 2.696178e+03 9.104770e+02]
 [0.000000e+00 0.000000e+00 1.000000e+00]]

# Image 0
R = [[ 0.86863263  0.37673212 -0.32179227]
 [-0.44287505  0.88156808 -0.16339952]
 [ 0.22212395  0.28444792  0.93260406]]
T = [-0.21416583 -0.2571567   0.16956859]


# Image 1
R = [[ 0.90208208  0.32308862 -0.28611477]
 [-0.29805909  0.94587646  0.1283686 ]
 [ 0.31210366 -0.03051991  0.94955771]]
T = [-2.40984019e-01  8.82576072e-05  4.76871846e-02]


# Image 2
R = [[ 0.96358973  0.20786754 -0.16818418]
 [-0.19664438  0.97712118  0.0810259 ]
 [ 0.18117898 -0.04500325  0.98241991]]
T = [-0.13990368  0.00922085  0.03539171]


# Image 3
R = [[ 0.99998207  0.00499065 -0.00330968]
 [-0.00499566  0.99998639 -0.00150651]
 [ 0.00330212  0.00152301  0.99999339]]
T = [0.00201909 0.00020396 0.01447096]

图像为3264x1840。给定点(1、0、0),(0、1、0),(0、0、1),(0、0、0)的结果是:

# Image 0
(6137.9883, -3908.1243)
(2598.4294, 4618.5454)
(1252.732, 1241.767)
(-1772.2549,  -3178.3713)

# Image 1
(6587.124, -1322.4381)
(14527.832, 149477.4)
(1498.1089, 1293.9762)
(-11991.927, 915.467)

# Image 2
(11887.4375, -1422.836)
(-17431.814, -275772.7)
(1552.5148, 1114.9052)
(-9024.983, 1612.931)

# Image 3
(153636.7, 183.5757)
(2814.6936, 169517.17)
(1618.4507, 905.79755)
(2009.2186, 948.4782)

0 个答案:

没有答案