简体   繁体   English

我已经安装了 OpenCV C++。 我可以在不重新安装库的情况下使用它在 Python 中的功能吗?

[英]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:关于我当前系统的信息:

  • OSX 10.13.6 OSX 10.13.6
  • opencv 3.4.3 (installed with homebrew) opencv 3.4.3(随自制软件安装)
  • python 3.6.10 python 3.6.10

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.

相关问题 如果我已经安装了Anaconda Python,如何在R中使用TensorFlow? - How to use TensorFlow in R if I have Anaconda Python already installed? 看来我安装了2个版本的os python 3。 理想情况下,我想将3.6.4用于pygame,但我有Tcl / Tk错误(我该如何解决?) - It seems I have 2 versions os python 3 installed. Ideally I Would want to use 3.6.4 for pygame but I have Tcl/Tk error(how do i fix this?) 我安装了 Python 3 x64、Python 2.7 x64 和 Python 2.7 x32。 如何使用 py 启动器切换到 Python 2.7 的 32 位版本? - I have Python 3 x64, Python 2.7 x64, and Python 2.7 x32 installed. How can I use py launcher to switch to the 32 bit version of Python 2.7? 我无法在Visual Studio Code上格式化Python文件:“没有安装用于'python'文件的文档格式化程序。” - I can't format Python file on Visual Studio Code: “There is no document formatter for 'python'-files installed.” “ModuleNotFoundError:没有名为 'kucoin' 的模块”,但我已经安装了它,还尝试重新安装,但结果相同。 运行 python 3.8.10 - "ModuleNotFoundError: No module named 'kucoin'" but I have it installed and also tried reinstalling but same result. Running python 3.8.10 我想为python3.6安装pip。 当我已经安装了另一个版本的 python3 时。 - I want to install pip for python3.6. When i allready have another version of python3 is installed. 如何在 python 中安装 plyer 库? 我已经安装了 plyer 模块,仍然收到“没有模块错误” - how to install plyer library in python? i have already installed plyer module , still am getting "no module error" 图书馆不在Pycharm中,即使我已经安装了它 - Library is not in Pycharm, even though i have already installed it 如果我已经安装了 Anaconda 发行版并想使用其他文本编辑器,是否需要安装 Python? - Do I need to install Python if I already have the Anaconda distribution installed and want to use other text editors? 我如何删除 python 2.7,因为我已经在 ubuntu 上安装了 3.6.5? - How can i remove python 2.7 as i already have 3.6.5 installed on ubuntu?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM