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

tch -> std

tch -> ndarray

ndarray -> tch

image -> tch

image -> opencv

opencv -> nalgebra

nalgebra -> opencv

opencv -> tch

tch -> opencv

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_63 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.

A Tensor which data reference borrows from a Mat. It can be dereferenced to a Tensor.

Enums

Describes the image channel order of a Tensor.

Traits

Type conversion that is analogous to From.

Type conversion that is analogous to Into.

Fallible type conversion that is analogous to TryFrom.

Fallible type conversion that is analogous to TryInto.