计算深度图像中像素到相机平面的角度

3

我有一张来自ToF相机(Kinect V2)的深度图像。我不知道像素大小,但我知道深度图像的分辨率为512x424。我还知道我拥有70.6x60度的视场角。

我之前在这里询问了如何获取像素大小。在Matlab中,代码如下所示。

亮度越高的像素,物体越近。

close all
clear all

%Load image
depth = imread('depth_0_30_0_0.5.png');
frame_width = 512;
frame_height = 424;

horizontal_scaling = tan((70.6 / 2) * (pi/180));
vertical_scaling = tan((60 / 2) * (pi/180));

%pixel size
with_size = horizontal_scaling * 2 .* (double(depth)/frame_width);
height_size = vertical_scaling * 2 .* (double(depth)/frame_height);

图像本身是一个旋转了30度的立方体,可以在这里看到:enter image description here
现在我想计算像素到摄像机平面的水平角度和垂直角度。
我尝试使用三角测量来完成这个任务,首先在水平方向上计算一个像素到另一个像素的Z距离,然后再在垂直方向上进行计算。我使用卷积来实现这个过程:
%get the horizontal errors
dx = abs(conv2(depth,[1 -1],'same'));
%get the vertical errors
dy = abs(conv2(depth,[1 -1]','same'));

接下来我通过 atan 函数进行计算,代码如下:

horizontal_angle = rad2deg(atan(with_size ./ dx));
vertical_angle = rad2deg(atan(height_size ./ dy));
horizontal_angle(horizontal_angle == NaN) = 0;
vertical_angle(vertical_angle == NaN) = 0;

这里展示了一个有希望的结果,如下所示:Vertical angle enter image description here
然而,使用像这样稍微复杂一点的图像,它被旋转了60°和30°,会得到相同角度的水平和垂直角度的图像,如下所示:vertical3060 horizontal3060
从两幅图像中相互减去后,可以得到以下图像-表明这两者之间存在差异:enter image description here
因此,我的问题是:如何证明这个概念?数学是否正确,只是测试用例选择不当?在两幅图像之间从水平到垂直角度的角度差太小了吗?计算中是否有任何错误?
1个回答

0

虽然我之前的代码看起来不错,但它有一个缺陷。我用较小的图像(5x5、3x3等)进行了测试,并发现由卷积产生的差异图像(dx、dy)会创建偏移量。由于差异图像比原始图像小,因此无法将差异图像(其中保存两个像素之间的差异)映射到像素本身。

为了快速修复,我进行了下采样。所以我改变了滤波器掩码为:

%get the horizontal differences
dx = abs(conv2(depth,[1 0 -1],'valid'));
%get the vertical differences
dy = abs(conv2(depth,[1 0 -1]','valid'));

并将角度函数更改为:

%get the angles by the tangent
horizontal_angle = rad2deg(atan(with_size(2:end-1,2:end-1)...
    ./ dx(2:end-1,:)))
vertical_angle = rad2deg(atan(height_size(2:end-1,2:end-1)...
    ./ dy(:,2:end-1)))

我还使用了填充函数,将角度映射调整为与原始图像相同的大小。

horizontal_angle = padarray(horizontal_angle,[1 1],0);
vertical_angle = padarray(vertical_angle[1 1],0);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接