使用自制程序在Mac OS X 10.9中构建OpenCV_Python

时间:2013-10-17 14:24:27

标签: python macos opencv build homebrew

我正在尝试使用自制软件将我的OpenCV从版本2.4.5更新到版本2.4.6.1。我跑的时候     brew upgrade opencv
我遇到以下错误:

==> Upgrading opencv
dyld: DYLD_ environment variables being ignored because main executable (/usr/bin/sudo) is setuid or setgid
==> Downloading http://downloads.sourceforge.net/project/opencvlibrary/opencv-unix/2.4.6.1/opencv-2.4
Already downloaded: /Library/Caches/Homebrew/opencv-2.4.6.1.tar.gz
==> cmake -DCMAKE_INSTALL_PREFIX=/usr/local/Cellar/opencv/2.4.6.1 -DCMAKE_BUILD_TYPE=None -DCMAKE_FIN
==> make
/usr/local/Library/ENV/4.3/c++ -fsigned-char -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -fdiagnostics-show-option -fno-omit-frame-pointer -msse -msse2 -msse3 -dynamiclib -Wl,-headerpad_max_install_names -o ../../lib/libopencv_java246.dylib -install_name /tmp/-5W3i/opencv-2.4.6.1/macbuild/lib/libopencv_java246.dylib CMakeFiles/opencv_java.dir/generator/src/cpp/converters.cpp.o CMakeFiles/opencv_java.dir/generator/src/cpp/core_manual.cpp.o CMakeFiles/opencv_java.dir/generator/src/cpp/jni_part.cpp.o CMakeFiles/opencv_java.dir/generator/src/cpp/Mat.cpp.o CMakeFiles/opencv_java.dir/generator/src/cpp/utils.cpp.o CMakeFiles/opencv_java.dir/generator/src/cpp/VideoCapture.cpp.o CMakeFiles/opencv_java.dir/core.cpp.o CMakeFiles/opencv_java.dir/imgproc.cpp.o CMakeFiles/opencv_java.dir/objdetect.cpp.o CMakeFiles/opencv_java.dir/features2d.cpp.o CMakeFiles/opencv_java.dir/video.cpp.o CMakeFiles/opencv_java.dir/highgui.cpp.o CMakeFiles/opencv_java.dir/ml.cpp.o CMakeFiles/opencv_java.dir/calib3d.cpp.o CMakeFiles/opencv_java.dir/photo.cpp.o CMakeFiles/opencv_java.dir/contrib.cpp.o -L/usr/local/include/../lib ../../lib/libopencv_core.2.4.6.dylib ../../lib/libopencv_imgproc.2.4.6.dylib ../../lib/libopencv_highgui.2.4.6.dylib ../../lib/libopencv_objdetect.2.4.6.dylib ../../lib/libopencv_flann.2.4.6.dylib ../../lib/libopencv_features2d.2.4.6.dylib ../../lib/libopencv_video.2.4.6.dylib ../../lib/libopencv_ml.2.4.6.dylib ../../lib/libopencv_calib3d.2.4.6.dylib ../../lib/libopencv_photo.2.4.6.dylib ../../lib/libopencv_legacy.2.4.6.dylib ../../lib/libopencv_gpu.2.4.6.dylib ../../lib/libopencv_ocl.2.4.6.dylib ../../lib/libopencv_nonfree.2.4.6.dylib ../../lib/libopencv_contrib.2.4.6.dylib -ltbb ../../lib/libopencv_gpu.2.4.6.dylib ../../lib/libopencv_photo.2.4.6.dylib ../../lib/libopencv_legacy.2.4.6.dylib ../../lib/libopencv_ocl.2.4.6.dylib ../../lib/libopencv_objdetect.2.4.6.dylib ../../lib/libopencv_video.2.4.6.dylib ../../lib/libopencv_ml.2.4.6.dylib ../../lib/libopencv_calib3d.2.4.6.dylib ../../lib/libopencv_features2d.2.4.6.dylib ../../lib/libopencv_highgui.2.4.6.dylib ../../lib/libopencv_imgproc.2.4.6.dylib ../../lib/libopencv_flann.2.4.6.dylib ../../lib/libopencv_core.2.4.6.dylib /usr/lib/libz.dylib -ltbb -framework OpenCL
brew: superenv removed: -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -L/usr/local/include/../lib
usr/local/Cellar/cmake/2.8.11.2/bin/cmake -E cmake_progress_report /tmp/-5W3i/opencv-2.4.6.1/macbuild/CMakeFiles 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
[100%] Built target opencv_java
make: *** [all] Error 2

构建OpenCV的Python绑定似乎失败了。我在我的Mac上安装了Java构建版本1.7.0_45-b18,并在系统上安装了Python 2.7.5以及Numpy 1.7.1。我想知道这里会出现什么问题。

进一步调试显示在构建OpenCV_Python时导致问题,这是构建停止的错误:

[ 85%] Building CXX object modules/python/CMakeFiles/opencv_python.dir/src2/cv2.cpp.o
cd /tmp/opencv-fc49/opencv-2.4.6.1/macbuild/modules/python && /usr/local/Library/ENV/4.3/c++   -DHAVE_ALLOCA -DHAVE_ALLOCA_H -DHAVE_CVCONFIG_H -DHAVE_LIBPTHREAD -DHAVE_UNISTD_H -DPYTHON_USE_NUMPY=1 -Dopencv_python_EXPORTS -fsigned-char -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -fdiagnostics-show-option -fno-omit-frame-pointer -msse -msse2 -msse3 -Wno-unused-function -fPIC -I/tmp/opencv-fc49/opencv-2.4.6.1/modules/python/src2 -I/tmp/opencv-fc49/opencv-2.4.6.1/modules/nonfree/include -I/tmp/opencv-fc49/opencv-2.4.6.1/modules/ocl/include -I/tmp/opencv-fc49/opencv-2.4.6.1/modules/gpu/include -I/tmp/opencv-fc49/opencv-2.4.6.1/modules/legacy/include -I/tmp/opencv-fc49/opencv-2.4.6.1/modules/contrib/include -I/tmp/opencv-fc49/opencv-2.4.6.1/modules/objdetect/include -I/tmp/opencv-fc49/opencv-2.4.6.1/modules/photo/include -I/tmp/opencv-fc49/opencv-2.4.6.1/modules/calib3d/include -I/tmp/opencv-fc49/opencv-2.4.6.1/modules/features2d/include -I/tmp/opencv-fc49/opencv-2.4.6.1/modules/highgui/include -I/tmp/opencv-fc49/opencv-2.4.6.1/modules/ml/include -I/tmp/opencv-fc49/opencv-2.4.6.1/modules/video/include -I/tmp/opencv-fc49/opencv-2.4.6.1/modules/imgproc/include -I/tmp/opencv-fc49/opencv-2.4.6.1/modules/flann/include -I/tmp/opencv-fc49/opencv-2.4.6.1/modules/core/include -I/tmp/opencv-fc49/opencv-2.4.6.1/macbuild/modules/python -I/tmp/opencv-fc49/opencv-2.4.6.1/modules/python/src -I/tmp/opencv-fc49/opencv-2.4.6.1/modules/python/include -I/tmp/opencv-fc49/opencv-2.4.6.1/macbuild -isystem /usr/local/include -isystem /usr/local/include/eigen3 -isystem /usr/local/opt/python/Frameworks/Python.framework/Versions/2.7/Headers -isystem /usr/local/lib/python2.7/site-packages/numpy/core/include    -o CMakeFiles/opencv_python.dir/src2/cv2.cpp.o -c /tmp/opencv-fc49/opencv-2.4.6.1/modules/python/src2/cv2.cpp
/tmp/opencv-fc49/opencv-2.4.6.1/modules/python/src2/cv2.cpp:227:9: error: no matching function for call to 'PyInt_Check'
if( PyInt_Check(o) )
    ^~~~~~~~~~~
/usr/local/include/pypy_decl.h:171:17: note: candidate function not viable: 1st argument ('const PyObject *' (aka 'const _object *')) would lose const qualifier
PyAPI_FUNC(int) PyInt_Check(PyObject *arg0);
                ^
/tmp/opencv-fc49/opencv-2.4.6.1/modules/python/src2/cv2.cpp:233:9: error: no matching function for call to 'PyFloat_Check'
if( PyFloat_Check(o) )
    ^~~~~~~~~~~~~
/usr/local/include/pypy_decl.h:142:17: note: candidate function not viable: 1st argument ('const PyObject *' (aka 'const _object *')) would lose const qualifier
PyAPI_FUNC(int) PyFloat_Check(PyObject *arg0);
                ^
/tmp/opencv-fc49/opencv-2.4.6.1/modules/python/src2/cv2.cpp:239:9: error: no matching function for call to 'PyTuple_Check'
if( PyTuple_Check(o) )
    ^~~~~~~~~~~~~
/usr/local/include/pypy_decl.h:397:17: note: candidate function not viable: 1st argument ('const PyObject *' (aka 'const _object *')) would lose const qualifier
PyAPI_FUNC(int) PyTuple_Check(PyObject *arg0);
                ^
/tmp/opencv-fc49/opencv-2.4.6.1/modules/python/src2/cv2.cpp:245:28: error: no matching function for call to 'PyTuple_GetItem'
        PyObject* oi = PyTuple_GET_ITEM(o, i);
                       ^~~~~~~~~~~~~~~~
/usr/local/include/tupleobject.h:14:26: note: expanded from macro 'PyTuple_GET_ITEM'
#define PyTuple_GET_ITEM PyTuple_GetItem
                         ^~~~~~~~~~~~~~~
/usr/local/include/pypy_decl.h:400:24: note: candidate function not viable: 1st argument ('const PyObject *' (aka 'const _object *')) would lose const qualifier
PyAPI_FUNC(PyObject *) PyTuple_GetItem(PyObject *arg0, Py_ssize_t arg1);
                       ^
/tmp/opencv-fc49/opencv-2.4.6.1/modules/python/src2/cv2.cpp:702:28: error: use of undeclared identifier 'PySequence_Fast_ITEMS'; did you mean 'PySequence_Fast_GET_SIZE'?
    PyObject** items = PySequence_Fast_ITEMS(seq);
                       ^~~~~~~~~~~~~~~~~~~~~
                       PySequence_Fast_GET_SIZE
/usr/local/include/pypy_decl.h:339:24: note: 'PySequence_Fast_GET_SIZE' declared here
PyAPI_FUNC(Py_ssize_t) PySequence_Fast_GET_SIZE(PyObject *arg0);
                       ^
/tmp/opencv-fc49/opencv-2.4.6.1/modules/python/src2/cv2.cpp:702:20: error: cannot initialize a variable of type 'PyObject **' (aka '_object **') with an rvalue of type 'Py_ssize_t' (aka 'long')
    PyObject** items = PySequence_Fast_ITEMS(seq);
               ^       ~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/opencv-fc49/opencv-2.4.6.1/modules/python/src2/cv2.cpp:741:27: error: use of undeclared identifier 'PySequence_Fast_ITEMS'; did you mean 'PySequence_Fast_GET_SIZE'?
            items_i = PySequence_Fast_ITEMS(seq_i);
                      ^~~~~~~~~~~~~~~~~~~~~
                      PySequence_Fast_GET_SIZE
/usr/local/include/pypy_decl.h:339:24: note: 'PySequence_Fast_GET_SIZE' declared here
PyAPI_FUNC(Py_ssize_t) PySequence_Fast_GET_SIZE(PyObject *arg0);
                   ^
/tmp/opencv-fc49/opencv-2.4.6.1/modules/python/src2/cv2.cpp:741:25: error: assigning to 'PyObject **' (aka '_object **') from incompatible type 'Py_ssize_t' (aka 'long')
            items_i = PySequence_Fast_ITEMS(seq_i);
                    ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/opencv-fc49/opencv-2.4.6.1/modules/python/src2/cv2.cpp:814:24: error: use of undeclared identifier 'PySequence_Fast_ITEMS'; did you mean 'PySequence_Fast_GET_SIZE'?
PyObject** items = PySequence_Fast_ITEMS(seq);
                   ^~~~~~~~~~~~~~~~~~~~~
                   PySequence_Fast_GET_SIZE
/usr/local/include/pypy_decl.h:339:24: note: 'PySequence_Fast_GET_SIZE' declared here
PyAPI_FUNC(Py_ssize_t) PySequence_Fast_GET_SIZE(PyObject *arg0);
                       ^
/tmp/opencv-fc49/opencv-2.4.6.1/modules/python/src2/cv2.cpp:814:16: error: cannot initialize a variable of type 'PyObject **' (aka '_object **') with an rvalue of type 'Py_ssize_t' (aka 'long')
PyObject** items = PySequence_Fast_ITEMS(seq);

有人可以帮忙建立OpenCV吗?

1 个答案:

答案 0 :(得分:0)

你可能会在Py *函数周围遇到编译错误,因为它无法在搜索目录中找到python包含。

我不会依赖库存python构建并建议通过python安装另一个版本。两个python构建可以在同一台机器上共存,但你最好依赖brew的安装。您可以通过检查“哪个python”指向/ usr / local / bin / python或启动python解释器时的版本来验证它。 GilberLee的评论指出了一些很好的步骤:Installing openCV 2.4.2 on Mac OS X 10.9 (Mavericks)

安装python view homebrew后,尝试重新安装opencv,看看是否通过了那些编译错误。