PureCV is a pure Rust rewrite of OpenCV's core and imgproc modules. The central type is Matrix<T> (row-major, contiguous Vec<T> buffer) in src/core/matrix.rs. No C/C++ FFI is allowed — every algorithm is implemented from scratch in safe Rust.
src/
├── core/ # Matrix type, arithmetic, structural ops, types, error handling
│ ├── matrix.rs # Matrix<T> struct — the cv::Mat equivalent
│ ├── arithm.rs # Element-wise ops, linear algebra, stats (add, norm, gemm, …)
│ ├── structural.rs # flip, rotate, transpose, split, merge, hconcat, vconcat
│ ├── types.rs # Point, Size, Rect, Scalar, BorderTypes, enums
│ ├── error.rs # PureCvError enum + Result<T> alias
│ └── utils.rs # border_interpolate, ParIterFallback (non-parallel shim)
├── imgproc/ # Image processing algorithms
│ ├── color.rs # cvt_color (RGB/BGR/Gray/RGBA conversions)
│ ├── filter.rs # blur, box_filter, gaussian_blur, median_blur, bilateral_filter
│ ├── edge.rs # canny, sobel, scharr, laplacian
│ ├── derivatives.rs
│ └── threshold.rs
├── features/ # Placeholder for feature detectors (FAST, ORB — not yet implemented)
└── lib.rs # Re-exports core, imgproc, features; defines prelude
- Reference sources live in
cpp_ref/opencv/— consult when porting algorithms. - Tests are co-located:
src/core/tests.rs,src/imgproc/tests.rs. - Benchmarks use Criterion:
benches/arithm_bench.rs,benches/imgproc_bench.rs.
- Zero-FFI: No
bindgen,cc, or C++ linking. Pure Rust only. - No
unsafe: Avoidunsafeblocks. Ifstd::archorpulpSIMD is required, justify why safe iterators failed. - Error handling: Return
Result<T, PureCvError>— neverpanic!orunwrapin library code. - License header: Every new
.rsfile must include the LGPL header from.agents/skills/license-header-adder/SKILL.mdwith{{FILENAME}}replaced by the file's basename.
Four feature combinations must be supported: parallel, simd, both, or none.
- Parallel (
rayon): Use internal macrosbinary_op!/binary_op_scalar!(seesrc/core/arithm.rs) that switch betweenpar_iteranditervia#[cfg(feature = "parallel")]. - When
parallelis disabled,src/core/utils.rsexportsParIterFallbackas a sequential shim. - SIMD (
pulp): Optional optimizations gated by#[cfg(feature = "simd")]. - Prefer
.chunks_exact(n)over.chunks(n)to help LLVM auto-vectorize.
- OpenCV parity: Mirror OpenCV function names in snake_case (
cvt_color,box_filter,copy_make_border). - Generics: All operations take
Matrix<T>with trait bounds likeT: Default + Clone + ToPrimitive + FromPrimitive + Send + Sync. - Module re-exports: Each module file (
core.rs,imgproc.rs) re-exports public symbols so users writepurecv::core::Matrix,purecv::imgproc::cvt_color. - Comments & docs in English.
# Format → Lint → Test (this exact order; CI rejects failures)
cargo fmt
cargo clippy
cargo test
# Run benchmarks
cargo bench
# Run examples
cargo run --example arithmetic
cargo run --example color_conversion
cargo run --example structural_ops- Branch from
dev, PR againstdev.mainis for stable releases only. - Conventional Commits required (enforced by
git-cliffchangelog):- Types:
feat,fix,perf,doc,refactor,test,chore - Scopes:
core,imgproc,simd,wasm,parallel - Example:
feat(imgproc): add bilateral_filter implementation
- Types:
- Read the C++ reference in
cpp_ref/opencv/modules/to extract the mathematical kernel. - Create the function in the appropriate submodule (
src/core/orsrc/imgproc/). - Use
Result<Matrix<T>, PureCvError>as the return type. - Gate parallel loops with
#[cfg(feature = "parallel")]and provide a sequential fallback. - Add tests in the module's
tests.rsand a Criterion benchmark inbenches/. - Re-export the function in the parent module file (
core.rsorimgproc.rs).