【问题标题】:SWIG Python bindings for OpenCV 2.0 with MacPortsOpenCV 2.0 与 MacPorts 的 SWIG Python 绑定
【发布时间】:2011-01-02 11:26:11
【问题描述】:

大家好,

我已经花了 3 天时间试图让 OpenCV Python 绑定发生,我有(完整的史诗般的斗争是 documented here)但是尽管在通过 macports 安装 swig 后在 CMake 中打开了 SWIG 标志,我'我没有得到任何 SWIG 操作:(

我的 cmake 命令看起来像:

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/opt/local -D BUILD_PYTHON_SUPPORT=ON -D BUILD_SWIG_PYTHON_SUPPORT=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D BUILD_EXAMPLES=ON -D BUILD_TESTS=ON -D PYTHON_INCLUDE_DIR=/opt/local/Library/Frameworks/Headers -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_SWIG_PYTHON_SUPPORT=ON -D CMAKE_CXX_COMPILER=/usr/bin/g++-4.2 -D CMAKE_C_COMPILER=/usr/bin/gcc-4.2 ..

导致此错误:

-- Looking for libavformat/avformat.h
-- Looking for libavformat/avformat.h - not found
-- Looking for ffmpeg/avformat.h
-- Looking for ffmpeg/avformat.h - not found

所以我猜它找不到我在的那个:

/opt/local/include/libavformat/avformat.h

我该怎么说呢?像

-D CMAKE_CXX_FLAGS="-I/opt/local/include" -D CMAKE_SHARED_LINKER_FLAGS="-L/opt/local/lib"

???

我正在通过 Macports 使用 OSX 10.5.8、Python 2.6 并编译最新的 OpenCV-trunk。

【问题讨论】:

    标签: python opencv cmake swig macports


    【解决方案1】:

    似乎 cmake 标志并没有太大的区别。我变得系统化并将它们减少到最低限度:

    cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/opt/local -D BUILD_PYTHON_SUPPORT=ON -D BUILD_SWIG_PYTHON_SUPPORT=OFF -D BUILD_NEW_PYTHON_SUPPORT=ON -D PYTHON_INCLUDE_DIR=/opt/local/Library/Frameworks/Python.framework/Headers -D CMAKE_CXX_COMPILER=/usr/bin/g++-4.2 -D CMAKE_C_COMPILER=/usr/bin/gcc-4.2 -D BUILD_SWIG_PYTHON_SUPPORT=ON ..
    

    我设法编译了所有内容,但是当我厌倦了“导入 cv”win Python 时,我不断收到以下错误:

    Fatal Python error: Interpreter not initialized (version mismatch?)
    

    这是因为darwin上的编译器默认是python的系统版本。我关注了some advice,发现这很有魅力:

    sudo chmod 000 /System/Library/Frameworks/Python.framework/
    cmake ...
    sudo chmod 755 /System/Library/Frameworks/Python.framework/
    

    【讨论】:

      【解决方案2】:

      如果您对较新的(非 SWIG)绑定没问题,恕我直言更好,您可以直接通过 MacPorts 安装:

      sudo port install opencv +python26
      

      sudo port install opencv +python27
      

      视情况而定。

      另见How to install OpenCV for python

      【讨论】:

      • 看起来 python 绑定是一个变种 - 需要 +python26 吗?
      猜你喜欢
      • 1970-01-01
      • 2012-01-14
      • 2011-12-10
      • 2011-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-10
      • 1970-01-01
      相关资源
      最近更新 更多