Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Algorithm 计算深度图像中像素与摄影机平面的角度_Algorithm_Matlab_Kinect_Angle_Depth Buffer - Fatal编程技术网

Algorithm 计算深度图像中像素与摄影机平面的角度

Algorithm 计算深度图像中像素与摄影机平面的角度,algorithm,matlab,kinect,angle,depth-buffer,Algorithm,Matlab,Kinect,Angle,Depth Buffer,我有一个ToF相机(Kinect V2)的z图像。我没有像素大小,但我知道深度图像的分辨率为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

我有一个ToF相机(Kinect V2)的z图像。我没有像素大小,但我知道深度图像的分辨率为
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度的立方体,可以在此处看到:

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

我试着用三角测量法来计算从一个像素到另一个像素的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°

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

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;

将两幅图像相减后,我得到了下图——这表明这两幅图像之间存在差异


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

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