[英]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.
我计划使用 tensorflow 进行训练,使用 opencv 进行数据采集和预处理。 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.
在之前的项目中,我已经在 C++ 中安装了 opencv,但是这次我想将我的所有代码保留在 python 中,以使一切都干净。
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?
如果是这样,有没有办法使现有的 opencv 库与 python 一起使用?
If you have a better suggestion, you are welcome to post it below.如果你有更好的建议,欢迎在下方留言。
Info about my current system:关于我当前系统的信息:
Compilation will be necessary only for the bindings.只有绑定才需要编译。 The python wrapper is generated from OpenCV's source.
python 包装器是从 OpenCV 的源代码生成的。 The stub code that gets generated has to be linked against Python and the OpenCV libraries.
生成的存根代码必须与 Python 和 OpenCV 库链接。
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.该过程从
modules/python/CMakeFiles.txt
中的 Cmake 文件开始,该文件应定义需要从 Python 提供的模块列表。 Next, the headers are grabbed and parsed from these by a python bindings generator script resident within OpenCV's source structure.接下来,通过驻留在 OpenCV 源结构中的 python 绑定生成器脚本从这些文件中抓取和解析这些标题。 The headers shall include function declarations etc which shall then be converted into wrapper functions by the same generator script.
标头应包括 function 声明等,然后应通过相同的生成器脚本将其转换为包装函数。
You could try to modify the cmake to exclude/include any module that you do not want to compile and build the bindings.您可以尝试修改 cmake 以排除/包含您不想编译和构建绑定的任何模块。 This will not recompile OpenCV
这不会重新编译 OpenCV
Please have a look at: OpenCV Python Bindings to understand in detail how the python bindings are being generated.请查看: OpenCV Python 绑定以详细了解如何生成 python 绑定。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.