This project implements a complete pipeline for 3D reconstruction from stereo images (left/right). It estimates depth (Z) and generates a 3D point cloud in millimeters.
The system is based on stereo vision:
- Two images of the same scene are captured
- Corresponding points are detected
- The horizontal difference (disparity) is used to compute depth
[ Z = \frac{f \cdot B}{d} ]
Where:
Z= depthf= focal length (pixels)B= baseline (mm)d= disparity
- Check file existence
- Load images using OpenCV
- Convert to landscape orientation
-
Load intrinsic matrix
K -
Convert portrait → landscape
-
Parameters:
- focal lengths (
fx,fy) - optical center (
cx,cy)
- focal lengths (
- Detect keypoints using SIFT
- Match descriptors using FLANN
- Apply Lowe’s ratio test (0.70)
cv2.findEssentialMat(...)- Computed using RANSAC
- Encodes the geometric relationship between views
cv2.recoverPose(...)-
Recovers:
- Rotation
R - Translation
t
- Rotation
cv2.stereoRectifyUncalibrated(...)- Aligns points horizontally
- Reduces vertical disparity
- Update intrinsic matrices:
K_rect = H @ Kdisp = pts_l[:,0] - pts_r[:,0]- Horizontal difference between matched points
cv2.triangulatePoints(P1, P2, ...)Using:
-
P1 = K[I | 0] -
P2 = K[R | t] -
Output is in homogeneous coordinates → converted to 3D
scale = BASELINE / ||t||
pts3d *= scale- Converts reconstruction to real-world units (mm)
-
Remove:
- points with Z < 0 (behind camera)
- NaN / infinite values
-
Apply outlier filtering (3σ rule)
-
2D projections (X-Z, Z-Y)
-
3D scatter plot
-
Export:
resultat_3d.pngnuage_points.ply
image_left_undist4.jpgimage_right_undist4.jpgcamera_K.npycamera_dist.npy(optional)
python main.py-
3D point cloud
-
Generated files:
points_3d.npypoints_3d.txtnuage_points.plyresultat_3d.png
-
Accuracy depends on:
- image quality
- calibration precision
- number of matches
-
Translation vector
tis normalized → scaling with baseline is required
- Use full stereo calibration (
stereoCalibrate) - Compute dense disparity maps (StereoBM / StereoSGBM)
- Add color/texture to point cloud
- Apply bundle adjustment for optimization
This project was developed as part of studies in computer vision and stereo vision.