Skip to content

Ndarray to Mat conversion. #588

Description

@ruseinov

I have been working on a python extension, using

pyo3 = "0.21.1"
numpy = "0.21.0"
opencv = { version = "0.92.0" , features = ["clang-runtime"]}

The main issue I'm facing now is that Python OpenCV code is now reading images as numpy arrays, so that's what I have to pass to Rust. But those numpy arrays have too many channels, so when I actually need to call any Rust OpenCV methods - I need to convert this back to Mat, but the reshape fails due to CV_CN_MAX, which is 512.
It seems there is some way of tackling this within the C++ OpenCV Python extensions. It'd be really nice to introduce a way of doing that for Rust too.

Here's the code in question:

    // channels variable is > 512
    let reshaped_mat = mat.reshape_nd(*channels, shape);

Here's some context: opencv/opencv#20070

It looks like the PythonWrapper knows how to convert these things back and forth, reshaping to fit the bill.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions