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

impl ToInputArray for Vector<BoxedRef<'_,Mat>> #555

Closed
sampaioletti opened this issue Apr 1, 2024 · 4 comments
Closed

impl ToInputArray for Vector<BoxedRef<'_,Mat>> #555

sampaioletti opened this issue Apr 1, 2024 · 4 comments

Comments

@sampaioletti
Copy link

sampaioletti commented Apr 1, 2024

Would it be possible to implement something like....

impl ToInputArray for Vector<BoxedRef<'_,Mat>>

or more general i.e. impl ToInputArray for Vector<T> where T:...

Happy to do a PR, just wondering if that is idiomatic, seems like with the new boxedref returns it would be handy.

Usecase: crating a Vector from a set of Mat::roi and using in hconcat

PS sorry for the initial issue create, I hit the wrong button.

@sampaioletti sampaioletti changed the title impl ToInputArray for Vector<BoxedRef< impl ToInputArray for Vector<BoxedRef<'_,Mat>> Apr 1, 2024
@twistedfall
Copy link
Owner

I think it makes perfect sense, thank you! If you feel like you can do the change I'm more than happy to review the PR, otherwise I will take a look at this in the coming days.

@sampaioletti
Copy link
Author

So after my first time going through the repo (awesome btw) initially my thought would be I would have to impl VectorElement and VectorExtern for BoxedRef to exist in a Vector something about that feels off, or impossible, but might be the correct way. Am I better off going a different route of impl ToInputArray for Vec<BoxedRef<'_,Mat>> or can you see another direction.

@twistedfall
Copy link
Owner

I would have to impl VectorElement and VectorExtern for BoxedRef to exist in a Vector

That's the way I would take. Currently to be able to create a Vector<T> at all you need to have:

  1. Vector<T>: VectorExtern<T> — this is the glue that connects Rust Vector to its std::vector C++ counterpart.
  2. T: VectorElement — this is currently kind of hack to allow more efficient conversion of vectors of copy types to Rust Vec.

And necessary impls for cases where T is BoxedRef are not being generated at the moment.

The generation for 1 is happening from this template: https://github.com/twistedfall/opencv-rust/blob/master/binding-generator/src/writer/rust_native/vector.rs#L62 (tpl/vector/rust_extern.tpl.rs). For 2 it's https://github.com/twistedfall/opencv-rust/blob/master/binding-generator/src/writer/rust_native/vector.rs#L65-L69 (tpl/vector/rust_copy_non_bool.tpl.rs and tpl/vector/rust_non_copy_or_bool.tpl.rs).

After that the generation of proper ToInputArray is still needed and it happens from https://github.com/twistedfall/opencv-rust/blob/master/binding-generator/src/writer/rust_native/vector.rs#L71 (tpl/vector/rust_input_output_array.tpl.rs)

@twistedfall
Copy link
Owner

This functionality is now available in 0.91.2 release

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