简体   繁体   中英

I already have OpenCV C++ installed. Can I use its functions in Python without reinstalling the library?

To begin with, I am setting up environment for a machine-learning project. I plan to use tensorflow for the training, and opencv for data acquisition as well as pre-processing. In a prior project, I already have opencv installed in C++, but this time I want to keep all my code in python in order to make everything clean.

Is my plan achievable? Do I need to reconfigure or recompile the library? If so, is there a way to make the existing opencv library work with python?

If you have a better suggestion, you are welcome to post it below.

Info about my current system:

  • OSX 10.13.6
  • opencv 3.4.3 (installed with homebrew)
  • python 3.6.10

Compilation will be necessary only for the bindings. The python wrapper is generated from OpenCV's source. The stub code that gets generated has to be linked against Python and the OpenCV libraries.

The process starts with the Cmake file at modules/python/CMakeFiles.txt which shall define the list of modules that needs to be made available from Python. Next, the headers are grabbed and parsed from these by a python bindings generator script resident within OpenCV's source structure. The headers shall include function declarations etc which shall then be converted into wrapper functions by the same generator script.

You could try to modify the cmake to exclude/include any module that you do not want to compile and build the bindings. This will not recompile OpenCV

Please have a look at: OpenCV Python Bindings to understand in detail how the python bindings are being generated.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM