-
Notifications
You must be signed in to change notification settings - Fork 7
/
RenderDepthMesh.m
executable file
·29 lines (21 loc) · 1.04 KB
/
RenderDepthMesh.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
function [DepthImageM, CameraCoordT] = RenderDepthMesh(FM, VM, CamParamS, ImageSizeV, ...
zNearFarV, zoomFactor, invertedDepth)
MexGlutInit;
if (~isa(FM, 'double'))
FM = double(FM);
end
DepthImageM = RenderDepthMeshImpl(FM, VM, CamParamS, ImageSizeV, ...
zNearFarV, zoomFactor);
%% converts the z buffer to real 3D value for easier reading.
% z algorithm from http://stackoverflow.com/questions/6652253/getting-the-true-z-value-from-the-depth-buffer
NormalizedZM = DepthImageM * 2 - 1.0;
RealZM = 2 * zNearFarV(1) * zNearFarV(2) ./ (zNearFarV(2) + zNearFarV(1)
- NormalizedZM * (zNearFarV(2) - zNearFarV(1)));
%% calculates the 3d coordinates from the real depth value. for the screen
[XM, YM] = meshgrid(1:ImageSizeV(2), 1:ImageSizeV(1));
RealXM = (XM - CamParamS.ccV(1)) / CamParamS.fcV(1) .* RealZM;
RealYM = (YM - CamParamS.ccV(2)) / CamParamS.fcV(2) .* RealZM;
CameraCoordT = cat(3, RealXM, RealYM, RealZM);
if (invertedDepth)
DepthImageM = 1 - DepthImageM;
end