PureCV

A high-performance, pure Rust computer vision library focusing on the core and imgproc modules of OpenCV. PureCV is built from the ground up to be memory-safe, thread-safe, and highly portable without the overhead of C++ FFI.
๐ฏ Philosophy
Unlike existing wrappers, PureCV is a native rewrite. It aims to provide:
- Zero-FFI: No complex linking or C++ toolchain requirements.
- Memory Safety: Elimination of segmentation faults and buffer overflows via Rust's ownership model.
- Modern Parallelism: Native integration with Rayon for effortless multi-core processing.
- WASM & Native SIMD: Optimized for the web and high-performance native architectures using explicit SIMD (via
pulp).
โจ Features
purecv-core
- Matrix Operations: Multi-dimensional
Matrix<T>with support for common arithmetic (add,subtract,multiply,divide) and bitwise logic (bitwise_and,bitwise_or,bitwise_xor,bitwise_not). Matrix and scalar variants for all operations. - Factory Methods: Intuitive initialization with
zeros,ones,eye, anddiag. - Comparison:
compare,compare_scalar,min,max,abs_diff,in_range. - Structural:
flip,rotate,transpose,repeat,reshape,hconcat,vconcat,copy_make_border,extract_channel,insert_channel. - Math:
sqrt,exp,log,pow,magnitude,phase,cart_to_polar,polar_to_cart,convert_scale_abs. - Stats:
sum,mean,mean_std_dev,min_max_loc,norm,normalize,count_non_zero,reduce. - Linear Algebra:
gemm,dot,cross,trace,determinant,invert,solve,solve_poly,set_identity. - Sorting:
sort,sort_idxwith configurable row/column and ascending/descending flags. - Clustering:
kmeanswith random, k-means++, and user-supplied initialization strategies. - Transforms:
transform(per-element matrix transformation),perspective_transform(projective / homography mapping). - Random Number Generation:
randu(uniform distribution),randn(normal/Gaussian distribution),set_rng_seed. - Channel Management:
split,merge,mix_channels. - Utilities:
add_weighted,check_range,absdiff,get_tick_count,get_tick_frequency. - ndarray Interop: Optional, zero-cost conversions to/from
ndarray::Array3via thendarrayfeature flag.
purecv-imgproc
- Color Conversions: High-performance
cvt_colorsupporting RGB, BGR, Gray, RGBA, BGRA and more. - Filtering:
blur,box_filter,gaussian_blur,median_blur,bilateral_filter. - Edge Detection:
canny,sobel,scharr,laplacian. - Thresholding:
thresholdwith multiple threshold types.
๐ Getting Started
Installation
Add the following to your Cargo.toml:
[]
= "0.1"
Feature Flags
| Flag | Default | Description |
|---|---|---|
std |
โ | Standard library support |
parallel |
โ | Multi-core parallelism via Rayon |
ndarray |
โ | Interop with the ndarray crate (zero-cost views & ownership transfers) |
simd |
โ | Explicit SIMD optimizations |
wasm |
โ | WebAssembly-specific optimizations |
To enable the ndarray feature:
[]
= { = "0.1", = ["ndarray"] }
Usage Example
use ;
use ;
ndarray Interoperability
With the ndarray feature enabled, you can convert between Matrix<T> and ndarray::Array3<T>:
use Matrix;
// Matrix โ ndarray (zero-cost view)
let mat = ones;
let view = mat.as_ndarray_view; // ArrayView3<f32>, shape (480, 640, 3)
// Matrix โ ndarray (ownership transfer)
let mat2 = ones;
let arr = mat2.into_ndarray;
// ndarray โ Matrix (guarantees contiguous C-order layout for SIMD/WASM)
let mat3 = from_ndarray;
// Also works via the From trait
let arr2 = zeros;
let mat4: = from;
Running Examples
Explore the capabilities of PureCV by running the provided examples:
# Basic matrix arithmetic
# Structural operations (flip, rotate, split/merge)
# Color conversion (RGB to Grayscale)
๐งช Testing & Benchmarking
Running Tests
PureCV uses a comprehensive suite of unit tests to ensure correctness and parity with OpenCV.
# Run all tests
Running Benchmarks
Performance is a core focus. You can run benchmarks to see the impact of SIMD and multi-threading on your architecture:
# Run all benchmarks
๐บ Roadmap
- Phase 1: Core Foundation - Matrix types, arithmetic, geometric utilities, and basic structural transforms.
- [/] Phase 2: Performance - SIMD optimizations and benchmarking vs OpenCV C++.
- Phase 3: WebAssembly - Specialized wrappers and multi-threading for the web.
- Phase 4: Image Processing - Advanced filtering, convolutions, and feature detection.
๐ License
This project is licensed under the LGPL-3.0 License.