mcv-rs
mcv-rs provides lightweight computer-vision primitives for automation loops.
It does not capture screens and it does not perform input; it consumes RGBA
frames from a capture backend such as msc-rs and returns coordinates or OCR
results that can be passed to touch/keyboard backends.
Features
| Feature | Capability |
|---|---|
| default | Core types only: RgbaFrame, Roi, MatchResult, VisionTemplate |
template-matching |
Image template matching via OpenCV |
multi-color |
Multi-point color matching via OpenCV |
ocr |
OCR via ocr-rs/MNN |
full |
Template matching, color matching, and OCR |
The default feature set is intentionally empty so consumers can depend on the core data types without requiring a local OpenCV or MNN toolchain. Enable only the backends you need, for example:
[]
= { = "0.1", = ["template-matching"] }
OCR is also opt-in because ocr-rs with the mnn-dynamic backend requires MNN
headers/libraries at build time and model files at runtime.
Zero-configuration boundary
| Use case | Extra configuration |
|---|---|
| Core data types only | None |
template-matching |
Enable the feature and provide a working OpenCV build environment |
multi-color |
Enable the feature and provide a working OpenCV build environment |
ocr |
Enable the feature, provide MNN headers/libs at build time, and provide OCR model files at runtime |
In other words, cargo add mcv-rs is intentionally zero-config but only exposes
the core abstractions. Actual recognition backends are opt-in because they rely
on native libraries.
API style
Recognition backends follow the same style as the other crates in this workspace:
new(...)for the simplest/default constructor.builder(...).xxx().open()for ergonomic customization.with_options(...)orfrom_path(..., options)for explicit option structs.
You can also change process-wide per-template-type defaults once during application startup:
set_default_image_threshold?;
set_default_color_threshold?;
set_default_ocr_threshold?;
set_default_ocr_case_sensitive;
set_default_ocr_thread_count?;
set_default_ocr_models?;
// Uses the new default threshold.
let image_template = new?;
let color_template = new?;
# Ok::
Explicit options and builder overrides still win over process-wide defaults. OCR model files remain explicit; threshold, case-sensitivity, and thread count can be configured globally.
Example
use ;
Use find_with_roi when the same template should be reused in different
regions:
use ;
Builder example:
use ;
let template = builder
.threshold?
.roi
.open?;
# Ok::
Multi-point color example:
use ;
After the one-time OCR configuration above, creating a text template only requires the text:
use OcrTemplate;
For an in-memory capture frame, find is available directly on
OcrTemplate; importing VisionTemplate is not required:
let mut frame = new?;
let result = template.find?;
# Ok::
Use OcrTemplate::builder(models) for per-template overrides. Serialized or
fully explicit configurations remain available through
OcrTemplate::with_options(OcrFindOptions { ... }).
OCR build requirements
When enabling ocr or full, provide MNN locations for the ocr-rs
mnn-dynamic backend:
$env:MNN_LIB_DIR = "C:\path\to\mnn\lib"
$env:MNN_INCLUDE_DIR = "C:\path\to\mnn\include"
cargo check -p mcv-rs --features ocr
At runtime, provide OCR model files through OcrModelFiles. On Windows, set
MNN_DLL_PATH to an explicitly trusted MNN.dll when the DLL is not already
available through the normal Windows loader search path. The runtime library is
never inferred from a caller-provided OCR model directory.