nim-opencv icon indicating copy to clipboard operation
nim-opencv copied to clipboard

[RFC] C++ API

Open mratsim opened this issue 4 years ago • 5 comments

It seems like the C API is going the way of the dodo https://answers.opencv.org/question/185693/is-c-api-alive-or-not/

Though I would be surprised if the embedded folks don't push back or decide to maintain their own C API.

The post mentions the code generator for the C++ API in Python that can be used:

  • https://docs.opencv.org/master/da/d49/tutorial_py_bindings_basics.html
  • https://github.com/opencv/opencv/tree/master/modules/python/src2

In terms of organization, we can:

  • either have a monorepo here
  • or spin up OpenCV C++ as a separate project, ideally under the SciNim umbrella https://github.com/SciNim

mratsim avatar Jan 10 '21 22:01 mratsim

Feel free to create a separate project. This repo is quite old now and I haven't done any OpenCV since then really.

dom96 avatar Jan 10 '21 23:01 dom96

If a wrapper must be made, I think that a better approach is to create a module in opencv_contrib like for Julia (https://github.com/opencv/opencv_contrib/tree/master/modules/julia)

I see two advantages:

  • Expose the project to the OpenCV community and maybe have some help.
  • Expose Nim language.

After, maybe use this project or create another to download and build OpenCV with Nim binding in the good place to use it in Nim.

Also, I tried Nimterop with OpenCV without succeed. Unfortunately there hasn't been much happening on the project for some time as if the main contributor has disappeared.

EchoPouet avatar Feb 19 '21 07:02 EchoPouet

I'm not touching OpenCV CMake even with a 100-foot pole. Lost too much time trying to deal with linking there.

  • https://github.com/opencv/opencv/issues/12766
  • https://github.com/opencv/opencv/issues/12771

Building OpenCV takes ages even on a beefy machine, from an ergonomics standpoint it's better to have people only require OpenCV installed (or have a downloader for a precompiled one) instead of expecting everyone to have GCC or Clang installed, a beefy machine and the time to wait on OpenCV install. And I'm not even talking about CMake, finding dependencies and linking.

mratsim avatar Feb 19 '21 10:02 mratsim

I have build OpenCV a lot and it can be complex and very long.

So you propose a project that generate automatically a binding of OpenCV with a script (nimscript of course). When you use it with nimble in your personal project, you have the binding code and OpenCV's compiled libraries with its dependencies for the good platform of course. The OpenCV building can make by the CI for several platforms.

This project can be in SciNim group and propose additional features.

EchoPouet avatar Feb 20 '21 15:02 EchoPouet

Futhark works great with C, but not yet with C++, but the C++ parsing is (mostly) already in place.

currently: 1- opir uses libclang to turn C header into JSON 2- futhark reads JSON and turns it into nim file with importc pragmas

But for C++ opencv2 process is halfway there:

  • opir is already capable of reading opencv2/core.hpp and possibly other files, but it requires to be upgraded to know what to do with C++ specific clang cursors elements, like Namespace and CXXMethod
  • futhark that reads CPP JSON and turn it into a nim file with importcpp pragmas is a TODO

JSON output opir -xc++ -I/usr/include/opencv4 opencv2/core.hpp | jq | ansi2txt > opencv2_core.json opencv2_core.txt

stderr only opir -xc++ -I/usr/include/opencv4 opencv2/core.hpp 2>&1 >/dev/null | ansi2txt > opencv2_stderr.txt opencv2_stderr.txt

arkanoid87 avatar Jun 22 '23 13:06 arkanoid87