计算深度图像中像素到摄像机平面的角度
问题描述:
我有来自ToF摄像机(Kinect V2)的z图像。我没有像素大小,但我知道深度图像的分辨率为512x424
。我也知道我有一个70.6x60
度的fov。计算深度图像中像素到摄像机平面的角度
我问过如何在here之前获得像素大小。在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);
我现在想要做的就是计算一个像素与摄像机平面的水平角以及摄像机平面的垂直角。
我试图用三角测量法来计算从一个像素到另一个像素的z距离,首先是水平方向,然后是垂直方向。我这样做了卷积:
%get the horizontal errors
dx = abs(conv2(depth,[1 -1],'same'));
%get the vertical errors
dy = abs(conv2(depth,[1 -1]','same'));
这之后我通过反正切计算的话,像这样:
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;
哪还给可喜的成果,这样的:
但是,使用这样一个更复杂的图像,它转过60°和30°。
还给用于水平和垂直角度相同的角度的图像,这看起来像这样:
彼此相减两个图像后,得到以下的图像 - 这表明这两者之间存在差异。
所以,我有以下问题:我怎么能证明这个概念?数学是否正确,测试用例选择不当?两幅图像的水平角度与垂直角度的角度差是否过近?计算中是否有错误?
答
虽然我以前的代码看起来不错,但它有一个缺陷。我用较小的图像(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);