6

我正在尝试使用自制软件将我的 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 吗?

4

1 回答 1

0

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

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

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

于 2014-10-31T10:55:46.483 回答