MATLAB: X, Y and Z co-ordinates from 3D point cloud are not accurate. Showing considerable error in X co-ordinates.

3d sceneco-ordinatesComputer Vision Toolboxstereo vision

I reconstruct 3D scene using MATLAB 2014b and using point cloud I have to find out the X,Y and Z co-ordinates of white object in scene. For this, I find out centroids of white objects in Image 1 (I1)and using that values (which are in pixels off-course) I extract X, Y and Z values. But when I compared these extract values with actual values (which I measured with scale from left camera or camera 1), there was huge difference in values. Then I notice that my actual image I1 is of 480×640 while my rectified image J1 is of 442×604. Then just for trial, I found the centroid of white object in J1 (using impixelinfo) and extract the values. These values are far better then I get using I1, but still there is an avg. error of 7.31 cm in X, 0.5 cm in Y and 4.0 cm in Z. I can tolerate 0.5 cm error, so Y co-ordinate is not problem but in X and Z co-ordinates I want more accuracy (with preferable image I1 because I have code to get centroids using I1 not J1). I calibrate my stereo camera many times and still the same problem. One more point I notice that as distance along X-axis from left camera increases my accuracy increases. I can't understand, why? I'm attaching my stereoParams and excel files showing error with this.

Best Answer

Hi Naseeb,
First, based on what you wrote, I would guess that you may be confusing camera 1 and camera 2. According to your stereoParams object, your cameras are 9.1 cm apart. So if you are measuring locations of objects relative to camera 2 instead of relative to camera 1 that would explain most of the error in X.
Second, please keep in mind that the world coordinate system (assuming that you are using disparity() and reconstructScene() has its origin at the principal point of camera 1, which is located somewhere inside the camera casing. So that becomes hard to measure. A better test of accuracy of the reconstruction would be to measure a distance between two points in the world.
So, please check that you don't have camera 1 and camera 2 mixed up. If that does not help, could you please post a sample pair of images? Also, please clarify how exactly you are doing the reconstruction. Are you calling rectifyStereoImages followed by disparity followed by reconstructScene? If so, then of course you should be using the rectified images to look up the 3D world coordinates.