Crate cv_convert
source · [−]Expand description
Data conversion among computer vision libraries.
Version Selection
This crate supports multiple dependency versions to choose from.
The choices of dependency versions are named accordingly as Cargo features.
For example, the feature nalgebra_0-30
enables nalgebra 0.30.x.
It allows to list crate version selections in Cargo.toml
.
[dependencies.cv-convert]
version = 'x.y.z'
features = [
'image_0-23',
'opencv_0-62',
'tch_0-6',
'nalgebra_0-30',
'ndarray_0-15',
]
Enable full
feature if you wish to enable all crates with up-to-date versions.
Traits
The traits FromCv and IntoCv provide .from_cv()
and .into_cv()
, and
traits TryFromCv and TryIntoCv provide .try_from_cv()
and .try_into_cv()
methods respectively.
Just like std’s From, Into, TryFromCv and TryIntoCv.
use cv_convert::{FromCv, IntoCv, TryFromCv, TryIntoCv};
use nalgebra as na;
use opencv as cv;
// FromCv
let cv_point = cv::core::Point2d::new(1.0, 3.0);
let na_points = na::Point2::<f64>::from_cv(&cv_point);
// IntoCv
let cv_point = cv::core::Point2d::new(1.0, 3.0);
let na_points: na::Point2<f64> = cv_point.into_cv();
// TryFromCv
let na_mat = na::DMatrix::from_vec(2, 3, vec![1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);
let cv_mat = cv::core::Mat::try_from_cv(&na_mat).unwrap();
// TryIntoCv
let na_mat = na::DMatrix::from_vec(2, 3, vec![1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);
let cv_mat: cv::core::Mat = na_mat.try_into_cv().unwrap();
//!
Supported conversions
The notations are used for simplicity.
S -> T
suggests the conversion is defined by non-fallible FromCv.S ->? T
suggests the conversion is defined by fallible TryFromCv.(&)T
means the type can be either owned or borrowed.&'a S -> &'a T
suggests that the target type borrows the source type.
opencv -> opencv
std -> tch
- owned/borrowed multi-dimensional array ->? Tensor
- (&)[T; N] ->? Tensor
- (&)[[T; N2]; N1] ->? Tensor
- … and so on up to 6 dimensions
tch -> std
- &’a Tensor -> &’a multi-dimensional array
- &’a Tensor -> &’a [T; N]
- &’a Tensor -> &’a [[T; N2]; N1]
- … and so on up to 6 dimensions
- (&)Tensor -> owned multi-dimensional array
- (&)Tensor ->? [T; N]
- (&)Tensor ->? [[T; N2]; N1]
- … and so on up to 6 dimensions
tch -> ndarray
ndarray -> tch
image -> tch
- (&)ImageBuffer ->? Tensor
- (&)DynamicImage ->? Tensor
image -> opencv
- (&)ImageBuffer ->? Mat
- (&)DynamicImage ->? Mat
opencv -> nalgebra
- (&)Mat ->? OMatrix
- (&)Point_
-> Point2 - (&)Point3_
-> Point2 - (&)OpenCvPose<(&)Point3d> ->? Isometry3
- (&)OpenCvPose<(&)Mat> ->? Isometry3
nalgebra -> opencv
- (&)OMatrix ->? Mat
- (&)Point2
-> Point_ - (&)Point3
-> Point3_ - (&)Translation<N, D> ->? Mat
- (&)Isometry3
->? OpenCvPose<Point3_ > - (&)Isometry3
->? OpenCvPose - (&)Isometry3
->? OpenCvPose
opencv -> tch
- (&)Mat ->? Tensor
- Mat ->? TensorFromMat
tch -> opencv
- (&)Tensor ->? Mat
- (&)TensorAsImage ->? Mat
OpenCV
If your system requires opencv/clang-runtime
to build, enable the opencv_0-62-clang-runtime
feature to solve.
Other versions are named accordingly.
Re-exports
pub use opencv_0_62 as opencv;
pub use image_0_23 as image;
pub use nalgebra_0_30 as nalgebra;
pub use ndarray_0_15 as ndarray;
pub use tch_0_6 as tch;
Modules
Structs
A pair of rvec and tvec from OpenCV, standing for rotation and translation.
A tensor with image shape convention that is used to convert to Tensor.
Enums
Describes the image channel order of a Tensor.