To run this project, you need to download the following datasets:
- KITTI Gray Version Dataset (22 GB): Download Link
Download and extract thegray
version of the KITTI odometry dataset, which contains image sequences. - Ground Truth Data (5 MB):
The ground truth file (e.g.,00.txt
) is included in the KITTI dataset under thesequences
folder.
Update the paths in test.py
to reflect your local dataset directories. For example:
cam = PinholeCamera(1241.0, 376.0, 718.8560, 718.8560, 607.1928, 185.2157)
vo = VisualOdometry(cam, '/path/to/sequences/00.txt')
traj = np.zeros((600, 600, 3), dtype=np.uint8)
for img_id in range(4541):
img_path = '/path/to/sequences/00/image_0/' + str(img_id).zfill(6) + '.png'
This project implements a Visual Odometry (VO) pipeline optimized for Python 3. The implementation uses SuperGlue for feature matching, providing superior accuracy compared to traditional feature matching methods. The project is adapted and improved from the original uoip/monoVO-python repository.
Below is an example trajectory visualization showing the comparison between the estimated path (green) and the ground truth path (red):
test.py
: Main script to run the visual odometry process and visualize the trajectory.visual_odometry.py
: Contains thePinholeCamera
andVisualOdometry
classes, utilizing SuperGlue for feature matching.
- SuperGlue Feature Matching: Utilizes SuperGlue, a transformer-based architecture, for accurate and robust feature matching between frames.
- Pose Estimation: Computes the camera's motion using the Essential Matrix and pose recovery methods.
- Trajectory Visualization: Draws the estimated trajectory alongside the ground truth trajectory for comparison.
- CUDA Support: The code automatically uses CUDA if a compatible GPU is detected, accelerating SuperGlue computations.
- Python 3 Compatibility: Fully optimized for Python 3.
This project requires the following libraries:
numpy
opencv-python
torch
(PyTorch)
Follow the official PyTorch installation guide to install the appropriate version for your system, including CUDA support if you have a compatible NVIDIA GPU. For example, to install the CUDA 11.8-compatible version of PyTorch, use:
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
Install numpy
and opencv-python
using pip:
pip install numpy opencv-python
-
Download KITTI Dataset:
- Download the KITTI Gray Version Dataset (22 GB) from the KITTI Odometry Benchmark.
- Extract the dataset and note the path to the
sequences
folder.
-
Ground Truth Data:
- The ground truth trajectory file (
00.txt
) can be found in the same dataset under thesequences/00/
directory.
- The ground truth trajectory file (
-
Update Paths:
Intest.py
, set the appropriate paths for both the image sequence and the ground truth:cam = PinholeCamera(1241.0, 376.0, 718.8560, 718.8560, 607.1928, 185.2157) vo = VisualOdometry(cam, '/path/to/sequences/00.txt') for img_id in range(4541): img_path = '/path/to/sequences/00/image_0/' + str(img_id).zfill(6) + '.png'
-
Set Camera Parameters: Update the
PinholeCamera
instance intest.py
with your camera's intrinsic parameters:cam = PinholeCamera(1241.0, 376.0, 718.8560, 718.8560, 607.1928, 185.2157)
-
Run the Script:
python test.py
-
Trajectory Visualization: Two windows will appear:
- Current Frame: Displays the current image being processed.
- Trajectory: Shows the estimated (green) and ground truth (red) trajectories.
-
The final trajectory image is saved as
map.png
in the working directory.
The code is optimized to run on a CUDA-compatible GPU if available. PyTorch will automatically detect the GPU and perform computations on the GPU for faster performance. If CUDA is not available, the code will fall back to CPU execution.
This project is based on uoip/monoVO-python and adapted with SuperGlue for improved performance.
This project is licensed under the MIT License.