MATLAB: 3D point cloud doesn’t show up.

3d plotscomputer visionComputer Vision Toolboxdigital image processingerrorImage Acquisition ToolboxMATLAB

I have been trying to get a Point Cloud from a live feed using 2 usb web cams with the following code.
As I run the code below a 3D plane shows up but no point cloud is displayed in that, the program keeps running for a long time but nothing comes up except the 3D plane.
MATLAB: R2015a
output_dir = 'C:\Users\HITESH\Desktop\Matlab';
%%set up webcam
delete(imaqfind)
leftCam = imaq.VideoDevice('winvideo', 2, 'YUY2_640x480');
rightCam = imaq.VideoDevice('winvideo', 1, 'YUY2_640x480');
%%load stereo parameters if required
if ~exist('stereoParams', 'var')
load stereocalibration.m;
end
ax = axes;
maxDepth = 5;
while true
imageLeft = step(rightCam);
imageRight = step(leftCam);
[J1, J2] = rectifyStereoImages(imageLeft, imageRight, stereoParams);
disp = disparity(rgb2gray(J1), rgb2gray(J2), 'DisparityRange', [0, 112]);
pointCloud = reconstructScene(disp, stereoParams) ./1000;
z = pointCloud(:,:,3);
z(z<0) = NaN;
z(z>maxDepth) = NaN;
pointCloud(:,:,3) = z;
if ~ishandle(ax)
break;
else
showPointCloud(pointCloud, J1, 'VerticalAxis', 'Y', 'VerticalAxisDir', 'Down', 'Parent', ax);
xlabel('X (mm)');
ylabel('Y (mm)');
zlabel('Z (mm)');
xlim(ax, [-.8, .8]);
ylim(ax, [-.8, .8]);
zlim(ax, [-.8, .5]);
drawnow;
end
end
release(leftCam);
release(rightCam);

Best Answer

Nothing would show up if all of the reconstructed z were < 0 or > maxDepth which is 5.
Beware that the units for depth are probably cm, so you are probably discarding anything further away than 5 cm.