This project implements a Visual Odometry (VO) pipeline in Python 3, optimized from an original Python 2 version. The code uses stereo camera images to estimate the position and orientation of a moving camera over time. The implementation leverages feature tracking and pose estimation to compute camera trajectories.
This work is based on the original repository by uoip, which has been adapted and optimized for Python 3 compatibility.
test.py
: Main script to run the visual odometry process.visual_odometry.py
: Defines classes and functions for visual odometry computation.
- Feature Tracking: Uses the Lucas-Kanade optical flow method to track feature points between consecutive frames.
- Pose Estimation: Estimates the camera's motion using the Essential Matrix and pose recovery techniques.
- Pinhole Camera Model: Simple pinhole camera model with support for distortion correction.
- Trajectory Visualization: Visualizes the estimated trajectory against the ground truth trajectory.
This project uses the following Python libraries:
numpy
opencv-python
To install the dependencies, run:
pip install numpy opencv-python
-
Set Camera Parameters: Update the
PinholeCamera
instance intest.py
with your camera's parameters:cam = PinholeCamera(1241.0, 376.0, 718.8560, 718.8560, 607.1928, 185.2157)
-
Load Ground Truth Data: Specify the path to the ground truth annotations file in the
VisualOdometry
class:vo = VisualOdometry(cam, '/path/to/your/annotations.txt')
-
Load Image Sequence: Specify the path to the image sequence:
img_path = '/path/to/your/images/' + str(img_id).zfill(6) + '.png'
-
Run the Script:
python test.py
- Trajectory Visualization: The script displays two windows:
- One showing the current frame being processed.
- Another showing the estimated trajectory (green) compared to the ground truth (red).
- Saved Map: The trajectory visualization is saved as
map.png
.
The main script performs the following steps:
- Initialize Camera: Create an instance of
PinholeCamera
. - Initialize Visual Odometry: Create an instance of
VisualOdometry
. - Image Loop:
- Load each image frame.
- Update visual odometry using
vo.update
. - Plot the estimated trajectory.
This file contains the core implementation for visual odometry.
-
PinholeCamera
Class:- Stores camera parameters and distortion coefficients.
-
VisualOdometry
Class:- Processes frames and estimates the camera's motion.
- Key Methods:
processFirstFrame
: Detects features in the first frame.processSecondFrame
: Estimates motion between the first and second frames.processFrame
: Updates motion estimation for subsequent frames.update
: Main function to process each new frame.
-
featureTracking
Function:- Tracks features between two frames using Lucas-Kanade optical flow.
This project was originally designed for Python 2. The following changes were made to ensure Python 3 compatibility:
- Updated
print
statements to Python 3 syntax. - Ensured
numpy
andOpenCV
functions work with Python 3. - Adjusted data types and array handling to match Python 3 requirements.
This project is adapted from the original implementation by uoip/monoVO-python.
This project is released under the MIT License.