2017-08-10 221 views
2

我有來自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); 

圖像本身是由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')); 

這之後我通過反正切計算的話,像這樣:

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°。

enter image description here

還給用於水平和垂直角度相同的角度的圖像,這看起來像這樣:

vertical3060 horizontal3060

彼此相減兩個圖像後,得到以下的圖像 - 這表明這兩者之間存在差異。

enter image description here

所以,我有以下問題:我怎麼能證明這個概念?數學是否正確,測試用例選擇不當?兩幅圖像的水平角度與垂直角度的角度差是否過近?計算中是否有錯誤?

回答

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