3D point cloud doesn't show up.

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

 Respuesta aceptada

Walter Roberson
Walter Roberson el 25 de Feb. de 2019

1 voto

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.

2 comentarios

Hitesh P
Hitesh P el 26 de Feb. de 2019
Thanks walter but I am not able to understand what I should I change in the code to get the pointcloud. Please help. Thanks in advance.
Walter Roberson
Walter Roberson el 26 de Feb. de 2019
increase the maxdepth to 500 if you want 5 meters .

Iniciar sesión para comentar.

Más respuestas (0)

Preguntada:

el 25 de Feb. de 2019

Comentada:

el 26 de Feb. de 2019

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by