RustCV is a high-performance, native Rust computer vision library designed to be a modern alternative to OpenCV. By leveraging Rust's memory safety and zero-cost abstractions, we provide a seamless, "C++-dependency-free" experience for vision developers and robotics engineers.
VideoCapture, Mat, and imshow, significantly reducing migration costs for developers coming from C++.async/await.Mat structures.🦀 Rust Native: Written entirely in Rust. Say goodbye to C++ shared library "dependency hell" and complex CMake configurations.
⚡ High Performance:
Integrated Lazy Global Runtime for automatic management of asynchronous drivers.
Supports Stride memory layout, allowing direct mapping of hardware buffers.
🎨 Out-of-the-box Functionality:
VideoIO: Native support for V4L2 (Linux); AVFoundation (macOS) is currently WIP.
HighGUI: Lightweight, cross-platform windowing based on minifb for real-time debugging.
ImgProc: Built-in drawing primitives (rectangles, text) and real-time FPS calculation.
ImgCodecs: Integrated with image for reading/writing all major image formats.
🛠️ Strong-Typed Configuration: No more "magic numbers." Use ergonomic APIs like cap.set_resolution(1280, 720).
The project is currently in a rapid iteration phase, and platform support is as follows:
| Platform | Backend Technology | Status | Development Plan |
|---|---|---|---|
| Linux | V4L2 | 🚀 Initial support, some core functions implemented | Full-scale development to complete full functionality adaptation and deployment. Currently supports MJPEG/YUYV decoding and hot reloading. |
| macOS | AVFoundation | 🚧 Under development, core function adaptation in progress | Continuous development to complete full functionality support and compatibility verification. |
| Windows | MediaFoundation | 📋 Development not yet started, no available functions | Included in the development plan, adaptation will begin after the core functions of the preceding platforms are stable. |
Add RustCV to your Cargo.toml:
[dependencies]
rustcv = "0.1"
use anyhow::Result;
use rustcv::prelude::*; // Import VideoCapture, Mat
use rustcv::highgui; // Import GUI
use rustcv::imgproc; // Import Drawing/Image Processing
fn main() -> Result<()> { (V4L2 on Linux)
// 1. Open the camera (index 0)
// The runtime is managed internally; no #[tokio::main] macro is required.
let mut cap = VideoCapture::new(0)?;
// 2. (Optional) Set resolution
cap.set_resolution(640, 480)?;
let mut frame = Mat::empty();
println!("🎥 Start capturing... Press ESC to exit.");
// 3. Main capture loop
while cap.read(&mut frame)? {
if frame.is_empty() { continue; }
// --- Image Processing ---
// Draw resolution info in the top-left corner
imgproc::put_text(
&mut frame,
&format!("Res: {}x{}", frame.cols, frame.rows),
imgproc::Point::new(10, 30),
1.0,
imgproc::Scalar::new(0, 0, 255) // Red
);
// Draw a green rectangle
imgproc::rectangle(
&mut frame,
imgproc::Rect::new(200, 200, 300, 300),
imgproc::Scalar::new(0, 255, 0), // Green
2
);
// Display window
highgui::imshow("RustCV Camera", &frame)?;
// Input Handling
if highgui::wait_key(1)? == 27 { // ESC
break;
}
}
Ok(())
}
Run
cargo run

We welcome all forms of contribution! Whether it's porting a new algorithm, improving documentation, or testing on new hardware.
git checkout -b feature/AmazingFeature).git commit -m 'Add some AmazingFeature').git push origin feature/AmazingFeature).Built with ❤️ by the RustCV Community.