How to get 3D point Cloud ?

23 views (last 30 days)
Hitesh P
Hitesh P on 22 Feb 2019
Answered: Hitesh P on 14 Mar 2019
Trying to get a pointcloud from live video feed using 2 usb webcams.
CODE:
output_dir = 'C:\Users\HITESH\Desktop\Matlab';
delete(imaqfind)
%%set up webcam
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;
clear maxdepth;
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 (m)');
ylabel('Y (m)');
zlabel('Z (m)');
xlim(ax, [-.8,.8]);
ylim(ax, [-.8,.8]);
zlim([ax,maxDepth]);
drawnow;
end
end
release(leftCam);
release(rightCam);
Error message:
Error using matlab.graphics.axis.Axes/horzcat
Cannot convert double value 5 to a handle.
How do I resolve this issue.
MATLAB R2015a
  1 Comment
Image Analyst
Image Analyst on 14 Mar 2019
The error message should give additional info, like the line number and the line of code that threw the error. Please give that also, if you're still having the problem.

Sign in to comment.

Answers (1)

Hitesh P
Hitesh P on 14 Mar 2019
The following error shows up when I run the code. A 3D plot shows up but no point cloud appears on that .
Error using matlab.graphics.axis.Axes/horzcat
Cannot convert double value 5 to a handle

Community Treasure Hunt

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

Start Hunting!