jerry73204 / rust-cv-convert

Type conversion among popular Rust computer vision libraries
MIT License
43 stars 21 forks source link

Help: Convert opencv image to ndarray #6

Closed Machine-Jonte closed 2 years ago

Machine-Jonte commented 2 years ago

Hello! This is a very promising package (thanks for putting in the effort of making it).

I've been struggling to figure out how to convert opencv::core::Mat -> Array3. Is this possible? Seems from the README the answer should be yes!

Following the README I expect to do something like:

    let img = opencv::imgcodecs::imread("./assets/demo_img.jpg", cv::imgcodecs::IMREAD_COLOR)?;
    let img: Array3<u8> = img.try_into_cv()?;
    // or
    let img: ArrayView3<u8> = img.try_into_cv()?;

This is my cargo.toml

...
[dependencies]
ndarray = "0.15.4"
opencv = {version = "0.63.0", features = ["clang-runtime"]}
cv-convert = {version = "0.17.2", features = ["ndarray_0-15", "opencv_0-63"]}
jerry73204 commented 2 years ago

According to the crate level doc (link), the direction opencv -> ndarray is not implemented yet. Perhaps you can open a feature request and let me find some time to work it out

Machine-Jonte commented 2 years ago

Yes, my mistake, I missed that in the docs. Thanks for the clarification.