How can i reconstruct 3D cloud from two images?

2 views (last 30 days)
I have two images I1 and I2.I have calibrated my camera using the checkerboard images using the camera calibration toolbox (computer vision toolbox 6.0).To reconstruct 3D object from 2D,i tried to use sample code given in matlab.But unfortunately it is returning out of memory eventhough i tried 3GB switch.Can anybody please give me the sample code to reconstruct the 3D object from 2 images.
Matlab version:2014a
Windows 7 Home 32bit
Ram-2GB.
Thank you in advance

Answers (1)

Dima Lisin
Dima Lisin on 14 Oct 2014
Hi Srinivasan,
Can you please tell me which function throws the out of memory error? Is it rectifyStereoImages? reconstructScene? How big are your images? Are they grayscale or color?
Without knowing the details, my general advice would be to use grayscale uint8 images. Also, I would highly recommend using a 64-bit machine.
  2 Comments
Srinivasan
Srinivasan on 15 Oct 2014
Edited: Srinivasan on 15 Oct 2014
Thanks for responding.At first i was using RGB images of dimension 2592 x 1944 (900 kb).And the error occurred while using the reconstructScene function. Now i done the 3GB switch and started using RGB images of dimension 1024 x 768 (Approximately 48kb). Now i get the disparity map and the rectified images but not able to see the pointcloud properly. Could you tell me how to view the pointCloud obtained?
Here's my code:
I1 = imread('JobL1.jpg');
I2 = imread('JobR1.jpg');
%Both cameras are same & have same parameter CameraParams. %CameraParams is calculated from MATLAB Camera Calibration App
stereoParams=stereoParameters(cameraParams,cameraParams,[0 0 0;0 0 0;0 0 0],[10;0;0])
% Rectify the images.
[J1, J2] = rectifyStereoImages(I1, I2, stereoParams);
% Display the images before rectification.
figure; imshow(cat(3, I1(:,:,1), I2(:,:,2:3)), 'InitialMagnification', 50); title('Before Rectification');
% Display the images after rectification.
figure; imshow(cat(3, J1(:,:,1), J2(:,:,2:3)), 'InitialMagnification', 50); title('After Rectification');
disparityMap = disparity(rgb2gray(J1), rgb2gray(J2));
figure; imshow(disparityMap, [0, 64], 'InitialMagnification', 50);
colormap('jet');
colorbar;
title('Disparity Map');
pointCloud = reconstructScene(disparityMap, stereoParams);
After this i am not sure how to view the pointcloud.I used the following command to view the pointcloud.
hAxes = gca;
X = pointCloud(:, :, 1);
Y = pointCloud(:, :, 2);
Z = pointCloud(:, :, 3).
plot3(hAxes, x, y, z, '.')
The pointcloud obtained is is really not resembling the images.Could you please tell me the right code/procedure to get the exact cloud? Once again i appreciate your effort for responding. Thanks
Dima Lisin
Dima Lisin on 11 Dec 2014
You are probably getting a lot of noise. What you should do is limit the range of the z values. First look at the histogram of the Z's. The valid z-values can be positive or negative, depending on whether your camera 1 is on the left or on the right. If valid Zs are positive, then set Z < 0 to NaN. You can also set Z > n to NaN, where n is the maximum distance you are interested in. If the Zs are negative, then you have to modify this accordingly.
If you set the z-values of noisy points to NaN, they will not be displayed by plot3.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!