【问题标题】:Calculate the angles of a pixel to a camera plane in a depth-image计算深度图像中像素与相机平面的角度
【发布时间】:2017-08-10 17:14:39
【问题描述】:

我有一张来自 ToF 相机 (Kinect V2) 的 z 图像。我没有像素大小,但我知道深度图像的分辨率为512x424。我也知道我的 fov 为70.6x60 度。

我在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);

图像本身是一个旋转了 30 度的立方体,可以在这里看到:

我现在要做的是计算像素与相机平面的水平角和与相机平面的垂直角。

我尝试通过三角测量来做到这一点,我计算从一个像素到另一个像素的 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;

这会带来有希望的结果,如下所示:

但是,使用像这样稍微复杂一点的图像,将其旋转 60° 和 30°。

返回水平和垂直角度相同的角度图像,如下所示:

将两个图像相互减去后,我得到以下图像 - 这表明这两个图像之间存在差异。

所以,我有以下问题:我如何证明这个概念?数学是否正确,而测试用例选择不当?两幅图像中水平角度和垂直角度的角度差是否太接近?计算有没有错误?

【问题讨论】:

    标签: algorithm matlab kinect angle depth-buffer


    【解决方案1】:

    虽然我之前的代码看起来不错,但它有一个缺陷。我用较小的图像(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);
    

    【讨论】:

      猜你喜欢
      • 2016-05-13
      • 1970-01-01
      • 2013-07-04
      • 2016-04-11
      • 2014-04-02
      • 2016-08-21
      • 1970-01-01
      • 1970-01-01
      • 2015-12-08
      相关资源
      最近更新 更多