Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't convert Mat to ndarray #13

Open
ignacio-dc opened this issue Jun 27, 2023 · 1 comment
Open

Can't convert Mat to ndarray #13

ignacio-dc opened this issue Jun 27, 2023 · 1 comment

Comments

@ignacio-dc
Copy link

Hello. i'm having issues trying to convert an OpenCV Mat to an ndarray, here is my code

use cv_convert::IntoCv;
use cv_convert::opencv as cv;
use cv_convert::ndarray as nd;

fn main() {

    let mat = cv::core::Mat::new_rows_cols_with_default(300,300,cv::core::CV_8UC3, cv::core::Scalar::all(1.)).unwrap();

    let view: nd::ArrayD<u8> = (&mat).into_cv();
}

The compiler gives me this error:

--> src/main.rs:10:39
   |
10 |     let view: nd::ArrayD<u8> = (&mat).into_cv();
   |                                       ^^^^^^^ the trait `FromCv<&Mat>` is not implemented for `ArrayBase<OwnedRepr<u8>, cv_convert::ndarray::Dim<IxDynImpl>>`
   |
   = help: the following other types implement trait `FromCv<T>`:
             <OPoint<T, cv_convert::nalgebra::Const<2>> as FromCv<&Point_<T>>>
             <OPoint<T, cv_convert::nalgebra::Const<2>> as FromCv<Point_<T>>>
             <OPoint<T, cv_convert::nalgebra::Const<3>> as FromCv<&Point3_<T>>>
             <OPoint<T, cv_convert::nalgebra::Const<3>> as FromCv<Point3_<T>>>
             <Point3_<T> as FromCv<&OPoint<T, cv_convert::nalgebra::Const<3>>>>
             <Point3_<T> as FromCv<OPoint<T, cv_convert::nalgebra::Const<3>>>>
             <Point<T> as FromCv<&Point_<T>>>
             <Point<T> as FromCv<Point_<T>>>
           and 116 others
   = note: required for `&Mat` to implement `IntoCv<ArrayBase<OwnedRepr<u8>, cv_convert::ndarray::Dim<IxDynImpl>>>`

I'm using rustc 1.69.0 and this is my cargo.toml

[dependencies]
cv-convert = "0.22.0"
@jerry73204
Copy link
Owner

This conversion is fallible. Please call try_into_cv() instead. I believe the API doc gives you this hint (&)Mat ->? Array.

let view: nd::ArrayD<u8> = (&mat).try_into_cv();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants