Production-grade Real-time Stereo Vision Ranging Solution
Supports UAV Obstacle Avoidance | Real-time Ranging | Robot Navigation | Industrial Applications
Quick Start โข Features โข Documentation โข Examples
- ๐ High-Performance Algorithm: SGBM (Semi-Global Block Matching) + WLS Filtering, improving accuracy by 30-50%.
- โก Real-time Processing: 25+ FPS @ 2560x720 resolution, meeting the latency requirements for drone obstacle avoidance.
- ๐ฏ Complete Workflow: Calibration โ Rectification โ Ranging โ Decision Making, ready for deployment out-of-the-box.
- ๐ ๏ธ Highly Configurable: JSON-based parameter managementโno code changes required for tuning.
- ๐ Rich Visualization: Real-time depth maps, distance heatmaps, and threat level indicators.
- ๐ Modular Design: A universal library that can be easily integrated into other computer vision projects.
- ๐ Developer Friendly: Detailed comments, comprehensive examples, and a robust calibration toolchain.
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Stereo Image Acquisition โ
โ (HBVCAM-W2307-2 / Universal Camera) โ
โโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Camera Calibration Module โ
โ โข Checkerboard Detection โข Intrinsic/Extrinsic โข Stereo Calibโ
โโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Image Rectification โ
โ โข Epipolar Alignment โข Distortion Removal โข ROI Cropping โ
โโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Disparity Calculation (SGBM + WLS) โ
โ โข Semi-Global Matching โข Edge Preservation โข Noise Filter โ
โโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Depth Estimation & 3D Point Cloud โ
โ depth = (focal_length ร baseline) / disparity โ
โโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโดโโโโโโโโโโโ
โผ โผ
โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ
โ Real-time Rangingโ โ UAV Avoidance โ
โ โข Mouse Interactionโ โ โข 9-Zone Analysisโ
โ โข Distance Displayโ โ โข Threat Eval โ
โ โข Visualization โ โ โข Flight Decisionโ
โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ
- Automatic checkerboard corner detection with sub-pixel accuracy.
- Supports Monocular and Stereo calibration.
- Multi-format output: JSON, NPZ, and Python Config.
- Calibration quality assessment reports and rectification previews.
- Click-to-measure: Query distance at any point via mouse (5x5 Median Filtering).
- Real-time Depth Mapping (JET Color Map).
- Color-coded status indicators (Near/Mid/Far).
- Effective range filtering (500mm - 6000mm).
- 9-Zone Analysis: Full field-of-view coverage.
- 5-Level Threat Assessment: From "Safe" to "Critical".
- Intelligent Decision Logic: Commands for Forward/Backward/Left/Right/Up/Down/Stop.
- Configurable Thresholds: All parameters tuned via
avoidance_config.json.
- OS: Windows / Linux / macOS
- Python: 3.8+
- Hardware: Stereo Camera (Recommended: HBVCAM-W2307-2)
# Clone the repository
git clone https://github.com/zhiqianzheng/StereoVision_Ranging.git
cd StereoVision_Ranging
# Create virtual environment
python -m venv venv
source venv/bin/activate # Linux/macOS
venv\Scripts\activate # Windows
# Install dependencies
pip install opencv-contrib-python numpy matplotlib scikit-image
cd two_vision_calibration/calibration_code
# 1. Capture 30-40 pairs of images
python capture.py # Press 's' to save, 'q' to quit
# 2. Run Calibration
python stereo_calibration.py
cd ../..
python real_time_distance_measurement.py
python drone_obstacle_avoidance.py
"distance_thresholds": {
"safe_distance_mm": 2000, // Green: Safe
"warning_distance_mm": 1500, // Yellow: Caution
"danger_distance_mm": 1000, // Orange: Warning
"critical_distance_mm": 500 // Red: Critical Danger
}
| Operation | CPU Latency | GPU Latency* | FPS (CPU) |
|---|---|---|---|
| Rectification | ~5ms | ~1ms | 200+ |
| SGBM Calculation | ~25ms | ~5ms | 40 |
| WLS Filtering | ~5ms | ~2ms | 200+ |
| Total Pipeline | ~40ms | ~9ms | 25 FPS |
*GPU acceleration requires
opencv-contrib-pythoncompiled with CUDA support.
โโโโโโโโโโโโฌโโโโโโโโโโโฌโโโโโโโโโโโ
โ Top Left โ Top Mid โ Top Rightโ Independent distance
โ (1/9) โ (1/9) โ (1/9) โ calculation per zone
โโโโโโโโโโโโผโโโโโโโโโโโผโโโโโโโโโโโค
โ Mid Left โ CENTER โ Mid Rightโ Center Zone Weight: 1.5x
โ (1/9) โ (1/9) โ (1/9) โ (Main Flight Direction)
โโโโโโโโโโโโผโโโโโโโโโโโผโโโโโโโโโโโค
โ Bot Left โ Bot Mid โ Bot Rightโ Top/Bot Weight: 0.8x
โ (1/9) โ (1/9) โ (1/9) โ
โโโโโโโโโโโโดโโโโโโโโโโโดโโโโโโโโโโโ
Q: Camera cannot open (Error 20).
A: Check the camera index in the code. On Linux, ensure you have permissions: sudo chmod 666 /dev/video*.
Q: High ranging error (> 10%).
A: Ensure you have 30+ high-quality calibration images. Check if the baseline_mm in JSON matches your hardware.
Q: High noise in disparity map.
A: Increase P1 and P2 in the SGBM configuration to enhance smoothness, or increase blockSize.
Contributions are what make the open-source community an amazing place to learn, inspire, and create.
- Fork the Project.
- Create your Feature Branch (
git checkout -b feature/AmazingFeature). - Commit your Changes (
git commit -m 'Add some AmazingFeature'). - Push to the Branch (
git push origin feature/AmazingFeature). - Open a Pull Request.
Distributed under the MIT License. See LICENSE for more information.
zhiqianzheng - GitHub Profile
่ฟๆ ทไฝ ็้กน็ฎ็่ตทๆฅๅฐฑ้ๅธธๅฝ้ ๅไธไธไธไบ๏ผ้่ฆๆๅ้ๅฏนๆไบๅ ทไฝ็ๆๆฏ็ป่ๅๅพฎ่ฐๅ๏ผ