GithubHelp home page GithubHelp logo

Comments (10)

kali avatar kali commented on August 21, 2024

I'll have a look to see if/how I can make it possible. I am also trying to get 3.1 to work.

from opencv-rust.

FuegoFro avatar FuegoFro commented on August 21, 2024

I looked into this a bit. It seems like the existing ptr(...) methods would do the trick here. They're currently ignored during generation because they return pointer types, specifically uchar*, but this is also a primitive type (based on the primitives dict in gen_rust.py). This is because the parse_type function checks for raw pointers before it checks for primitive types. Changing the ordering there such that it looks for primitives first allows it to generate the ptr(...) functions.

This leads to a second problem. There are two versions of every ptr(...) overload, one that's const (and returns a const uchar*) and one that's normal. However, the generator doesn't take constness into account when generating the C++ methods (or at least it doesn't seem to; I haven't read through enough to fully understand the const support). In any case, it generates two C++ methods with the exact same signature, which then fails to compile (complaining about redefining a symbol).

There's a few solutions I've thought of (and probably many I that haven't :P):

  1. Take constness into account when generating the C++ methods (specifically in the method signatures).
  2. Determine the set of things that go into a method and then coalesce methods so that we only generate each unique method once.
  3. Extend the functionality for ignoring methods to be able to take the attributes of the method into account (eg constness).
  4. Some entirely different approach for accessing the pixel data :)

What do you think a reasonable approach would be?

from opencv-rust.

kali avatar kali commented on August 21, 2024

Well, these methods are specifically enough that we may not want to generate them but just write them:
The generator is already very messy. This is because a huge lot of "c++ features" are used across opencv with or without consistency. This situation is actually a bit better in 3.x . Also, as soon as the pkg-config mess will improve in opencv size, we should be able to switch to the cv3 branch, where the generator has already been extensively modified.

Bottom line: it's not worth digging a trench in the generator just to support features used by one or two methods.

But instead, we can add these methods manually. I used this at the beginning, but it should still work: just add a Trait for these methods and impl it in the rust code in src, and put the matching C wrappers in native/something.cpp. The builder will compile and link code in native/*.cpp in the library along with the generated code.

Tell me what you think.

from opencv-rust.

phdoerfler avatar phdoerfler commented on August 21, 2024

I guess hand writing them is the best option. I'd like to help with that but unfortunately it exceeds my current rust knowledge by far (I still don't quite get how rust can even access C++. Even the rust manual says that only C is supported by the FFI). However if someone was willing to remote pair (e.g. via floobits) I'd love to give it a shot.

from opencv-rust.

kali avatar kali commented on August 21, 2024

Yeah. Rust does not call c++. The generator creates a C interface on top of the c++ class for rust FFI to talk to. The generated c interface is then built into a library by build.rs.

from opencv-rust.

phdoerfler avatar phdoerfler commented on August 21, 2024

Any news on this?

from opencv-rust.

FuegoFro avatar FuegoFro commented on August 21, 2024

I took a stab at one of the approaches for fixing this in #19. The solution worked for me, was a bit more general than handwriting, and didn't actually end up complicating the generator too much (at least, in my opinion). Even if it doesn't get merged in, you could probably patch it in locally @phdoerfler.

from opencv-rust.

kali avatar kali commented on August 21, 2024

Merged, built, and just released as 0.2.3 . Thanks again for the PR.

from opencv-rust.

phdoerfler avatar phdoerfler commented on August 21, 2024

Awesome! Thanks for doing this @FuegoFro

from opencv-rust.

FuegoFro avatar FuegoFro commented on August 21, 2024

Woo! No problem :)

from opencv-rust.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.