如何在 Ubuntu 16.04 上的 Anaconda 环境中将 OpenCV C++ 代码与 python 代码集成?

How can I integrate OpenCV C++ code with python code in Anaconda environment on Ubuntu 16.04?

我需要在 Anaconda 环境中使用我系统上的 ArUco C++ library for a part of my project where my main programming language is Python. I could not install python wrapper for ArUco。它只是抛出错误。所以我想我可以用 C++ 在 OpenCV 中安装和编写代码,并将结果传输到我的主要 Python 代码。可能吗?

您还可以使用 boost python 轻松地用 C++ 编写 python 函数!

http://www.boost.org/doc/libs/1_63_0/libs/python/doc/html/index.html

// non-compiling example:
namespace py = boost::python;
// you have access to all python builtins using the py:: namespace
py::list create_list(py::dict dictionary, py::tuple tuple);

为了很好的传递OpenCV数据to/frompython,有numpy支持:

http://www.boost.org/doc/libs/1_63_0/libs/python/doc/html/numpy/tutorial/ndarray.html

// non-compiling example:
namespace np = boost::python::numpy;
np::ndarray modify_image(np::ndarray image);

我不确定opencv数据是否可以直接使用……可能是。

你们要检测ArUco制造商吗?如果是这样,您可以尝试使用 contrib 模块的 OpenCV 3.2,其中包含一个 ArUco marker detection (aruco module) module. This Aruco in opencv 网页有 python 代码示例。

您可以从 site 为 Python 3.5 或 3.6 Windows 32 位或 64 位上的 contrib 预构建二进制文件获取 OpenCV3.2平台。它可以通过 pip install {filename}.whl 安装到 Anaconda,因为 conda install 不支持 whl 文件。