3D矩阵透视变换 [英] 3D matrix perspective transform

查看:159
本文介绍了3D矩阵透视变换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用阴影中的形状来生成使用安装在移动平台上的相机拍摄的图像的数字地形模型(DTM).用Python编写的算法似乎运行得很好,但是输出是倾斜的并且有点球形,所以我怀疑我需要从DTM中消除透视失真和桶形.

I am using shape from shading to generate a Digital Terrain Model (DTM) of an image taken using a camera mounted on a mobile platform. The algorithm written in Python seems to work reasonably well however the output is at an incline and a bit spherical so I'm suspecting that I need to remove perspective distortion and barrelling from the DTM.

此处可用,以防有人有兴趣获得去这个吧.

The data is available here in case anyone is interested in having a go at this.

摄像机以41度倾斜安装,并具有以下摄像机和失真矩阵:

The camera is mounted at an inclination of 41 degrees and has the following camera and distortion matrices:

    cam_matrix = numpy.matrix([[246.00559,0.00000,169.87374],[0.00000,247.37317,132.21396],[0.00000,0.00000,1.00000]])
    distortion_matrix = numpy.matrix([0.04674, -0.11775, -0.00464, -0.00346, 0.00000])

如何应用透视变换并从该矩阵中消除桶形失真以获得平坦的DTM?

How can I apply perspective transform and remove the barreling distortion from this matrix to obtain a flattened DTM?

我尝试使用OpenCV进行此操作,但是由于OpenCv期望图像,所以它不起作用,并且变换只是在移动像素而不是操纵它们的值.我还研究了Numpy和Scipy,但尚未得出结论或解决方案.我对这些转换背后的理论有些熟悉,但主要用于2D版本.

I have attempted this using OpenCV but it doesn't work as OpenCv is expecting an image and the transforms simply move pixels around rather than manipulate their value. I have also researched Numpy and Scipy but haven't arrived to a conclusion or a solution yet. I am somewhat familiar with the theory behind these transforms but have mostly worked on 2D versions.

有什么想法吗?

推荐答案

您可以使用4 x 4转换矩阵,该矩阵是不可逆的,并且可以在所需的两个坐标系之间进行双向转换.

You can use a 4 x 4 transformation matrix which is inversible and allows a bi-directional tranformation between the two coordinate systems that you want.

如果使用右手法则分别知道三个旋转abg,分别约为xyz. x0y0z0是两个坐标系原点之间的转换.

If you know the three rotations a, b and g, about x, y, z respectively, using the right-hand rule. The x0, y0, z0 are the translations between the origins of the two coordinate systems.

转换矩阵定义为:

T = np.array([[ cos(b)*cos(g), (sin(a)*sin(b)*cos(g) + cos(a)*sin(g)), (sin(a)*sin(g) - cos(a)*sin(b)*cos(g)), x0],
              [-cos(b)*sin(g), (cos(a)*cos(g) - sin(a)*sin(b)*sin(g)), (sin(a)*cos(g) + cos(a)*sin(b)*sin(g)), y0],
              [        sin(b), -sin(a)*cos(b), cos(a)*cos(b), z0]
              [ 0, 0, 0, 1])

要有效地使用它,您应该将点放置在二维数组中,例如:

To use it efficiently you should put your points in a 2-D array like:

orig = np.array([[x0, x1, ..., xn],
                 [y0, y1, ..., yn],
                 [z0, z1, ..., zn],
                 [ 1,  1, ...,  1]])

然后:

new = T.dot(orig)

将为您提供转换点.

这篇关于3D矩阵透视变换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆