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

2024-10-01 04:46:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要消除图像像素坐标的失真——并需要返回校正后的坐标。我不希望返回一个未失真的图像——只是像素的校正坐标。相机已经校准,我有相机的内在参数,和失真矩阵。我在python3中使用OpenCV

我已经阅读了尽可能多的理论和问题,我可以找到这里。关键信息是: https://docs.opencv.org/2.4/doc/tutorials/calib3d/camera_calibration/camera_calibration.html

这非常清楚地描述了需要考虑的径向畸变和切向畸变。 径向:

x{corrected}=x(1+k\u 1 r^2+k\u 2 r^4+k\u 3 r^6) y{corrected}=y(1+k\u 1 r^2+k\u 2 r^4+k\u 3 r^6)

切向:

x{corrected}=x+[2p\u 1xy+p\u 2(r^2+2x^2)] y{corrected}=y+[p_1(r^2+2y^2)+2p_2xy]

我怀疑我不能简单地按顺序应用这些更正。也许有一个函数可以直接做我想做的事情,不管怎样——我很想听听这个。你知道吗

我不能简单地在图像上使用正常的不失真程序,因为我试图将红外相机的失真校正应用于同一个相机的深度数据。如果你不失真这样的深度图像-你分割坐标像素,答案没有意义。希望我的想法是对的。你知道吗

迄今为止的准则:

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坐标矩阵——每个矩阵元素代表一个原始像素。你知道吗

谢谢你的帮助!你知道吗


Tags: thetoin图像imagefornp矩阵