Calculation of distance (z-axis) to object using CVST

I am facing an issue while using Computer Vision System Toolbox, while calculating the 3D distance to an object from a stereo set-up.
I have calibrated my stereo setup (mean reprojection error of <0.2 pixels). The checkerboard used for calibration are all within a range of 1m to 2.5m away from camera (z-axis).
However, I am not able to get a good stereo reconstructed image. It seems very noisy along the z-axis.
This is my code:
I1 = imread('A1r.png');
I2 = imread('B1r.png');
[I1_r, I2_r] = rectifyStereoImages(I1, I2, stereoParams);
[J1,J2] = PreProcessing(I1_r,I2_r); figure, imshow(J1); figure, imshow(J2); % PreProcessing() is uploaded
pointCloudDisp = Disparity_Reconstruct( J1, J2, stereoParams ); % Disparity_Reconstruct() is uploaded
DisplayReconstructedScene( pointCloudDisp, J1 );
I have uploaded stereoParameters and the object images on dropbox . Kindly refer these. The object (wheel) is kept around 1.5m away from setup (along z-axis).
The disparity is around 105 (when manually calculated).
Any inputs regarding how I can improve my reconstructed scene would be useful. Kindly let me know if any other information has to be shared
Also, is this the only way by which I can get the object distance? Can I somehow use triangulation here? (If so, how can i find the corresponding matching points in left and right images?)

Answers (1)

Hi Meghana,
The first thing I see is that if your images are RGB, you are doing disparity only on the blue channel. The better thing to do would be to use rgb2gray instead.
The other thing that seems odd, is the BlockSize of 55. That seems too large. I would try smaller values.
If that doesn't help, try applying histogram equalization using histeq to the images, before computing disparity.
Once you get your disparity map to look reasonable, then you should limit the z-values further. I would set minZ to 0, and maxZ to something like 2000. If your units are millimeters then 45000 mm is 45 meters, which is way too much, if your object is 1.5 meters away from the cameras.

3 Comments

Hello Dima,
FYI, this is a continuation of the same issue I had posted earlier. (I have decreased the resolution of my camera now, to decrease disparity)
I had used rgb2gray earlier. I didn't get good results (infact, it was pretty much the same issue). Hence, since the wheel appears slightly blue, I tried my algorithm by extracting the 3rd component.
I have implemented histeq and imgaussfilt, according to your suggestion ( given to to Mahdi ). This is included in my function named PreProcessing which I have attached.
I have tried a BlockSize of 15 as well, but it didn't help.
And yes, I am aware of this point and shall limit my z values (in terms of mm) when I get a proper disparity map.
Hi Meghana,
Try setting the disparity range to [0 128]. Also, try other values for BlockSize. Something between 15 and 25.
I would still advise that you use rgb2gray, though. It helps to have actual pixel values in all parts of the image, so that most pixels get a valid disparity.
Dima,
I had already tried changing the disparity to [0,128]. This time, since my z-axis had values lying in negative range, I changed the disparity to [-128,0].
Thanks. My stereo reconstructed image looks good now.
But why is the disparity in the negative range? Is it because I had rotated the cameras towards each other (So w.r.t Camera 1, the corresponding points in Camera 2's image lies in the other direction. Correct?)
Regards,
Meghana.

Sign in to comment.

Asked:

on 20 May 2015

Commented:

on 21 May 2015

Community Treasure Hunt

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

Start Hunting!