OpenCV 2.0 与 MacPorts 的 SWIG Python 绑定

发布于 2024-08-17 18:55:12 字数 1213 浏览 5 评论 0原文

你们大家,

我已经花了 3 天的时间试图让 OpenCV Python 绑定发生,并且我已经做到了(完整的史诗般的斗争是 记录在此处),但是尽管在通过 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-主干。

Y'all,

I've been at to for 3 days trying to get OpenCV Python binds happening, and I have (the full epic struggle is documented here) but despite turning the SWIG flag on in CMake after installing swig via macports, I'm not getting any SWIG action :(

My cmake command looks like:

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 ..

which pulls this error:

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

SO I guess its not finding the one i have at:

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

How do I tell it about that? With something like

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

???

I'm using OSX 10.5.8, Python 2.6 via Macports and compiling the latest OpenCV-trunk.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

青巷忧颜 2024-08-24 18:55:12

似乎 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的系统版本。我遵循了一些建议,发现这很有魅力:

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

Seems that the cmake flags didn't make much of a difference. I became systematic and reduced them to the minimum:

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 ..

and I managed to compile everything, but when I tired to "import cv" win Python I kept getting the following error:

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

which is because the compiler on darwin defaults to the system version of python. I followed some advice and found this worked like a charm:

sudo chmod 000 /System/Library/Frameworks/Python.framework/
cmake ...
sudo chmod 755 /System/Library/Frameworks/Python.framework/
少钕鈤記 2024-08-24 18:55:12

如果您对较新的(非 SWIG)绑定感到满意(恕我直言,这更好),您可以直接通过 MacPorts 安装:

sudo port install opencv +python26

sudo port install opencv +python27

根据需要进行安装。

另请参阅如何安装适用于 python 的 OpenCV

If you're ok with the newer (non-SWIG) bindings, which imho are better anyway, you can just install directly via MacPorts:

sudo port install opencv +python26

or

sudo port install opencv +python27

as appropriate.

See also How to install OpenCV for python

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文