python - 返回未失真的像素坐标而不是图像
问题描述
我需要不扭曲图像的像素坐标——并且需要返回校正后的坐标。我不希望返回未失真的图像 - 只是像素的校正坐标。相机已校准,我有相机内在参数和失真矩阵。我在 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_{修正} = 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_{校正} = 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 坐标矩阵——每个矩阵元素代表一个原始像素。
谢谢你的帮助!
解决方案
推荐阅读
- mysql - 使用选择总和查询来查找总和的最大值和最小值
- javascript - 如何在 ace 编辑器中实现 mathquill?
- java - How do I use on method to get the sizes of two different-sized arrayslists?
- python - 抓取谷歌搜索的推荐搜索部分,我该怎么办?
- python - 使用 pip 安装 scitools-iris 失败:ImportError No module named target_pkg (in pyke)
- swift - 在不使用 .barTintColor 的情况下设置导航栏的颜色?
- java - 如何根据事件类型处理事件
- python-3.x - 为什么设置类对象实例的属性会导致 AttributeError?
- javascript - 在帖子上请求对象为空
- mysql - 我的数据库存储在 AWS RDS 上。不幸的是,我的 aws rds 实例已被删除。它存储在我的计算机中的哪个位置