返回未失真的像素坐标,而不是图像

时间:2019-06-11 00:33:37

标签: python image opencv matrix distortion

我需要取消扭曲图像的像素坐标-需要返回校正后的坐标。我不希望返回未失真的图像,而只是返回像素的校正坐标。相机已经过校准,我有相机的固有参数和失真矩阵。我在python 3中使用OpenCV

我已经阅读了尽可能多的理论,并在这里提出了疑问。关键信息是: https://docs.opencv.org/2.4/doc/tutorials/calib3d/camera_calibration/camera_calibration.html

这很清楚地描述了需要考虑的径向变形和切向变形。 放射状:

x_ {更正} = x(1 + k_1 r ^ 2 + k_2 r ^ 4 + k_3 r ^ 6) y_ {corrected} = y(1 + k_1 r ^ 2 + k_2 r ^ 4 + k_3 r ^ 6)

切线:

x_ {更正} = x + [2p_1xy + p_2(r ^ 2 + 2x ^ 2)] y_ {corrected} = y + [p_1(r ^ 2 + 2y ^ 2)+ 2p_2xy]

我怀疑我不能简单地顺序应用这些更正。无论如何,也许有一个函数可以直接执行我想做的事情,而我很想知道这一点。

我不能简单地对图像使用正常的不失真程序,因为我试图将IR摄像机的失真校正应用于来自同一摄像机的深度数据。如果您不对这样的深度图像进行扭曲-您将像素划分为多个坐标,则答案毫无意义。希望我在这个方向上正确。

到目前为止的代码:

import numpy as np
import cv2
imgIR = cv2.imread("/20190529-150017-305-1235-depth.png",0)
#you could try this on any image...

h,  w = imgIR.shape[:2]

X = np.array([i for i in range(0,w)]*(h))
X = X.reshape(h, w)

Y = np.array([[i]*(w) for i in range(0,h)])

fx =    483.0 #x focal length
fy =    490.2
CentreX = 361.4 #optical centre of the image - x axis
CentreY = 275.6

#Relative to the optical centre, it is possible to determine the `#coordinates of each pixel in the image` 
#then do the above operation without loops using a scalar subtraction
Xref = X - CentreX
Yref = Y - CentreY

#"scaling factor" refers to the relation between depth units and meters;
scalingFactor = 18.0/36.0 # 18pixels / 36 mm;
# I'm not sure what should be yet -- whether [pixels at the shelf]/mm
#or mm/[pixels at the shelf]

Z = imgIR / scalingFactor


#using numpy
Xcoord = np.multiply(Xref,Z/fx)
Ycoord = np.multiply(Yref,Z/fy)

#how to correct these coords for the radial and tangential distortion?
#parameters as returned for the distortion matrix using 
cv2.calibrateCamera
dstvec = array([[-0.1225, -0.0159, 0.001616, -0.0018924,-0.00120696]]) 

我正在寻找的是一个新的X坐标不变的矩阵(已去除径向和切向畸变)和一个Y坐标不变的矩阵,每个矩阵元素代表一个原始像素。

感谢您的帮助!

0 个答案:

没有答案