- #1
PainterGuy
- 940
- 70
I'm trying to perform depth estimation on stereo vision using live feed. I'm using two webcams. The code below doesn't give any error but I only get a block box without any sign of live video! Could you please give it a look?
Matlab:
leftCam = imaq.VideoDevice('winvideo', 1, 'MJPG_320x240');
rightCam = imaq.VideoDevice('winvideo', 3, 'MJPG_320x240');
leftCam.ReturnedDataType = 'uint8';
leftCam.DeviceProperties.WhiteBalanceMode = 'manual';
rightCam.ReturnedDataType = 'uint8';
rightCam.DeviceProperties.WhiteBalanceMode = 'manual';
if ~exist('stereoParams','var')
load stereocalibration
end
% Run 3D image reconstruction on live video
ax = axes;
maxDepth = 5 ;
while true
imageLeft = step(rightCam);
imageRight = step(leftCam);
% Rectify
[J1, J2] = rectifyStereoImages(imageLeft, imageRight, stereoParams, 'OutputView','Full');
J1 = rgb2gray(J1);
J2 = rgb2gray(J2);
%Compute Disparity Map
disp = disparity(J1, J2)%, 'DisparityRange', [0, 112]);
% Reconstruct 3D scene from Disparity Map
pointCloud = reconstructScene(disp, stereoParams)./1000;
% Remove all points greater then maxDepth m away from the camera
z = pointCloud(:,:,3);
z(z < 0) = NaN;
z(z > maxDepth) = NaN;
pointCloud(:,:,3) = z;
% Continue running until figure window is closed
if ~ishandle(ax)
break;
else
pcshow(pointCloud, J1, 'VerticalAxis', 'Y','VerticalAxisDir', 'Down', 'Parent', ax);
xlabel('X (m)');
ylabel('Y (m)');
zlabel('Z (m)');
xlim(ax, [-.8, .8]); %-0.8 to 8
ylim(ax, [-.8, .8]); %-0.8 to 8
zlim(ax, [0, maxDepth]);
daspect(ax,'manual');
pbaspect(ax,'manual');
drawnow;
end
endrelease(leftCam)
release(rightCam)