RustCV:用现代 Rust 重新定义的 OpenCV 兼容视觉处理框架
组织介绍
RustCV Logo

📷 RustCV

English | 简体中文

Build Status Platform License Rust

RustCV 🦀

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.

📖 Introduction

  • OpenCV Parity: Provides familiar APIs such as VideoCapture, Mat, and imshow, significantly reducing migration costs for developers coming from C++.
  • Hidden Complexity: The backend is powered by a Tokio-based asynchronous driver, while exposing a clean, synchronous blocking interface. You get the performance of async I/O without the boilerplate of async/await.
  • Zero-Copy Design: Implements intelligent Buffer Swapping technology to achieve zero-copy data flow from kernel-space drivers directly to user-space Mat structures.

✨ Key Features

  • 🦀 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).

🖥️ Platform Support

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.

📦 Quick Start

Add RustCV to your Cargo.toml:

[dependencies]
rustcv = "0.1"

Basic Example: Camera Stream

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

RustCV Camera

🤝 Contributing

We welcome all forms of contribution! Whether it's porting a new algorithm, improving documentation, or testing on new hardware.

  1. Fork the repository.
  2. Create your feature branch (git checkout -b feature/AmazingFeature).
  3. Commit your changes (git commit -m 'Add some AmazingFeature').
  4. Push to the branch (git push origin feature/AmazingFeature).
  5. Open a Pull Request.

Built with ❤️ by the RustCV Community.

成就
1
Star
0
Fork
成员(1)
25125 lyonrust 1703239260
Leon

搜索帮助