cv-convert: Convert computer vision data types in Rust
Type conversions among famous Rust computer vision libraries. It supports the following crates:
Usage
Run cargo add cv-convert to add this crate to your project. In the
default setting, up-to-date dependency versions are used.
If you desire to enable specified dependency versions. Add
default-features = false and select crate versions as Cargo
features. For example, the feature nalgebra_0-30 enables nalgebra
0.30.x.
[]
= 'x.y.z' # Please look up the recent version on crates.io
= false
= [
'image_0-24',
'opencv_0-84',
'tch_0-13',
'nalgebra_0-32',
'ndarray_0-15',
]
The minimum supported rustc is 1.51. You may use older versions of
the crate (>=0.6) in order to use rustc versions that do not support
const-generics.
Cargo Features
opencv
opencv_0-84opencv_0-83opencv_0-82opencv_0-81opencv_0-80opencv_0-79opencv_0-78opencv_0-77opencv_0-76opencv_0-75opencv_0-74opencv_0-73opencv_0-72opencv_0-71opencv_0-70opencv_0-69opencv_0-68opencv_0-67opencv_0-66opencv_0-65opencv_0-64opencv_0-63
image
image_0-24image_0-23
imageproc
imageproc_0-23
ndarray
ndarray_0-15
nalgebra
nalgebra_0-32nalgebra_0-31nalgebra_0-30nalgebra_0-29nalgebra_0-28nalgebra_0-27nalgebra_0-26
tch
tch_0-13
Usage
The crate provides FromCv, TryFromCv, IntoCv, TryIntoCv traits, which are similar to standard library's From and Into.
use ;
use nalgebra as na;
use opencv as cv;
// FromCv
let cv_point = new;
let na_points = from_cv;
// IntoCv
let cv_point = new;
let na_points: Point2 = cv_point.into_cv;
// TryFromCv
let na_mat = from_vec;
let cv_mat = try_from_cv?;
// TryIntoCv
let na_mat = from_vec;
let cv_mat: Mat = na_mat.try_into_cv?;
Contribute to this Project
Add a new dependency version
To add the new version of nalgebra 0.32 for cv-convert for example,
open cv-convert-generate/packages.toml in the source repository. Add
a new version to the list like this.
[]
= ["0.26", "0.27", "0.28", "0.29", "0.30", "0.31", "0.32"]
= true
= []
Run make generate at the top-level directory. It modifies Rust
source files automatically. One extra step is to copy the snipplet in
cv-convert/generated/Cargo.toml.snipplet and paste it to
cv-convert/Cargo.toml.
Add a new type conversion
To add a new type conversion, take image::DynamicImage and
opencv::Mat for example. Proceed to cv-convert/src and implement
the code in with_opencv_image.rs because it is a conversion among
opencv and image crates.
Choose FromCv or TryFromCv trait and add the trait implementation
on image::DynamicImage and opencv::Mat types. The choice of
FromCv or TryFromCv depends on whether the conversion is fallible
or not.
// or
License
MIT license. See LICENSE file.