Implementation of stereo vision in Python using image pairs from the Middlebury dataset.
The main idea is: given a left and right photo of the same scene, we compute a disparity map and then estimate a depth map.
I used OpenCV’s built-in stereo matchers:
- StereoBM (Block Matching)
- StereoSGBM (Semi-Global Block Matching)
This project is mainly for learning + experimenting with parameters (disparity range, block size, etc.) and seeing how they affect the result.
- Takes a rectified stereo pair (left/right)
- Computes a disparity map
- Converts disparity to a depth map (approximate)
- Saves output images (and/or displays them)
- Python 3.x
- OpenCV (
opencv-python) - NumPy
Example install:
pip install opencv-python numpyIf you have a
requirements.txt, use:
pip install -r requirements.txtThis project uses stereo pairs from the Middlebury dataset.
You need to download the dataset separately (it’s not included in this repo).
- Dataset version: Middlebury 2021
Right now you said the command is:
python main- Compares small windows (blocks) between the left and right image
- Faster and simpler
- Usually noisier / more “blocky” results
- Uses a smoother optimization idea compared to BM
- Often produces cleaner disparity maps
- Slower but typically better quality
Depth is inversely related to disparity. A common approximate relationship is:
depth ≈ (focal_length * baseline) / disparity
If calibration values aren’t available, the depth map is often “relative” (useful for visualization, but not exact meters).
A native OpenCV build lives under cpp/ (CMake + optional vcpkg manifest). It mirrors the Python pipeline: same calibration and stereo matchers, disparity → depth, visualization and optional export.
See cpp/README.md for configure, build, and run instructions.
- Python, OpenCV, NumPy
- C++20, OpenCV 4 (see
cpp/)