Rover written with RUST
Set-up in x64 Debian for development
2025.10.27 21:14
* Steps to set up a RUST development environment for Rover on a Debian x64 PC first for development. The requirements are, I need to get stereo camera image to get 3D depth either using OpenCV or any other means for visual odometry.
Setting up a Rust development environment for a Rover on a Debian x64 PC with stereo vision capabilities involves several key steps, focusing on installing Rust, setting up OpenCV, and configuring your project for 3D depth estimation and visual odometry.
1. Install Rust and Cargo
The primary way to install Rust is through rustup, the Rust toolchain installer.
-
Install
rustup: Open your terminal and run the official installation script.
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
Follow the on-screen instructions (the default installation is usually fine).
2. Update your shell environment: After installation, you may need to source your shell's profile file (like ~/.bashrc or ~/.zshrc) or open a new terminal for the changes to take effect.
source $HOME/.cargo/env
3. Verify installation: Check the versions of the Rust compiler (rustc) and the package manager (cargo).
rustc --version
cargo --version
If you see version numbers, the installation was successful.
2. Install OpenCV Dependencies on Debian
The opencv Rust crate is a set of bindings that requires the underlying C++ OpenCV library to be installed on your system.
-
Update package lists:
sudo apt update
2. Install OpenCV and its dependencies: You'll need the development files. Installing from the Debian repositories is the easiest way to get started, though it might not be the absolute latest version.
sudo apt install libopencv-dev
For a more advanced setup or the latest version, you might need to compile OpenCV from source, including modules like opencv_contrib which contain features like SIFT/SURF for visual odometry, but this is a much longer process.
3. Create a Rust Project and Add Dependencies
Use Cargo to create a new project for your Rover's code.
-
Create the project:
cargo new rover_vo
cd rover_vo
2. Add the opencv crate: Edit your Cargo.toml file to add the opencv dependency. You should check the official opencv crate documentation for the latest compatible version.
Ini, TOML
# Cargo.toml
[dependencies]
opencv = "0.96.0" # Use the latest stable version you find
Note: The opencv crate bindings rely on the locally installed C++ library version.
4. Implement Stereo Vision for Depth and Visual Odometry
The core requirement is to get 3D depth and use it for visual odometry.
Stereo Camera Setup (Hardware)
First, your stereo camera must be calibrated and rectified. This process is typically done using OpenCV (often with Python or C++ tools) to:
-
Find the intrinsic parameters of each camera (focal length, principal point, distortion coefficients).
-
Find the extrinsic parameters (rotation and translation between the two cameras).
-
Use these to rectify the images so that the epipolar lines are horizontal, simplifying the search for corresponding points.
Depth Estimation (Disparity Map)
In your Rust code, you will use the opencv crate for the following logic:
-
Capture stereo frames: Use the
videoiomodule in OpenCV to grab synchronized frames from both your left and right cameras.
<Rust>
// Example Rust logic (pseudo-code)
use opencv::prelude::*;
use opencv::{videoio, highgui, calib3d, imgproc};
fn compute_depth() -> opencv::Result<()> {
// 1. Load your pre-calculated rectification maps (or load the calibration data and compute them)
// 2. Capture synchronized left and right images (Mat's)
let mut left_frame = Mat::default();
let mut right_frame = Mat::default();
// 3. Rectify the images using the loaded maps (remap function)
// 4. Compute the Disparity Map (depth is inversely proportional to disparity)
let mut disparity = Mat::default();
let sgbm = calib3d::StereoSGBM::create(...)?.into(); // Configure parameters like min_disparity, num_disparities, etc.
sgbm.compute(&left_frame, &right_frame, &mut disparity)?;
// 5. Convert Disparity to Depth (using your stereo camera's focal length (f) and baseline (B))
// Depth (Z) = f * B / disparity
Ok(())
}
Visual Odometry
Visual Odometry (VO) estimates the camera's motion between consecutive frames.
-
Feature Detection & Matching: Detect features (e.g., ORB, SIFT, or KAZE) in the current frame and match them with features in the previous frame.
-
Motion Estimation:
-
Stereo VO: Use the 3D point cloud derived from your stereo depth estimation and the matched 2D features to estimate the 6-DoF (Degrees of Freedom) transformation (Rotation and Translation ) between frames. This often involves algorithms like the PnP (Perspective-n-Point) algorithm using 3D-to-2D correspondences.
-
Monocular VO (Less recommended for a Rover requiring absolute scale): If you use only one camera, you estimate motion up to a scale factor using the Essential Matrix, and you'd need an external source (like the Rover's wheel encoders) to recover the absolute scale. Since you have a stereo camera, use the depth information to get a properly scaled trajectory.
-
-
Track Aggregation: Concatenate the rotations and translations over time to track the Rover's trajectory.
This video provides an overview of how to perform depth estimation from stereo images using OpenCV, which is the foundational step for your visual odometry pipeline. Stereo Vision Project: Depth Estimation with OpenCV in Python
Comment 0
| No. | Subject | Author | Date | Views |
|---|---|---|---|---|
| 8 |
Fifth : Visual Odometry
| me | 2025.10.28 | 0 |
| 7 |
Fourth-3 : Filtering Data
| me | 2025.10.28 | 0 |
| 6 |
Fourth-2 : Shrink down data count (4x4 block)
| me | 2025.10.28 | 0 |
| 5 |
Fourth : Depth Map
| me | 2025.10.28 | 0 |
| 4 |
Third : Rectify calibrated result
| me | 2025.10.28 | 0 |
| 3 | Second : Calibration using checker board [1] | me | 2025.10.28 | 0 |
| 2 |
First : Stereo Camera's image generation for calibration
| me | 2025.10.28 | 0 |
| » | Set-up in x64 Debian for development | me | 2025.10.27 | 0 |