在 centos 上为 python 从源代码安装 opencv

Installing opencv from source for python on centos

我安装了CentOS6.5。我安装了 python 2.7.9。我从源代码构建它。使用 pip 安装的 numpy 1.9.1。

我正在尝试从源代码安装 opencv 2.4.10。我 运行 使用 root 权限从 opencv src 目录执行命令。

mkdir build

cd build

cmake ../ -DCMAKE_BUILD_TYPE=RELEASE \
-DCMAKE_INSTALL_PREFIX=/usr/local \
-DBUILD_EXAMPLES=ON \
-DBUILD_NEW_PYTHON_SUPPORT=ON \
-DINSTALL_PYTHON_EXAMPLES=ON \
-DPYTHON_EXECUTABLE=/usr/local/bin/python2.7 \
-DPYTHON_INCLUDE_DIR=/usr/local/include/python2.7/ \
-DPYTHON_LIBRARY=/usr/local/lib/libpython2.7.so.1.0 \
-DPYTHON_NUMPY_INCLUDE_DIR=/usr/local/lib/python2.7/site-packages/numpy/core/include/numpy \
-DPYTHON_PACKAGES_PATH=/usr/local/lib/python2.7/site-packages/ \
-DBUILD_PYTHON_SUPPORT=ON


make

我遇到以下错误。

[ 76%] Generating generated0.i
Generated 377 functions
Scanning dependencies of target opencv_python
[ 76%] Building CXX object modules/python/CMakeFiles/opencv_python.dir/src2/cv2.cpp.o
/usr/src/opencv-2.4.10/modules/python/src2/cv2.cpp:15:33: error: numpy/ndarrayobject.h: No such file or directory
/usr/src/opencv-2.4.10/modules/python/src2/cv2.cpp: In member function ‘virtual void NumpyAllocator::allocate(int, const int*, int, int*&, uchar*&, uchar*&, size_t*)’:
/usr/src/opencv-2.4.10/modules/python/src2/cv2.cpp:184: error: ‘NPY_UBYTE’ was not declared in this scope


/usr/src/opencv-2.4.10/modules/python/src2/cv2.cv.hpp:423: warning: ‘cvmat_methods’ defined but not used [-Wunused-variable]
make[2]: *** [modules/python/CMakeFiles/opencv_python.dir/src2/cv2.cpp.o] Error 1
make[1]: *** [modules/python/CMakeFiles/opencv_python.dir/all] Error 2

你能帮忙吗?

我使用“--enable-shared”标志构建 python 我注释掉了第 50 行 string(MD5 hash "${lines}") /usr/src/opencv- 2.4.10/cmake/cl2cpp.cmake

-DPYTHON_NUMPY_INCLUDE_DIR=/usr/local/lib/python2.7/site-packages/numpy/core/include

去掉拖尾/numpy应该没问题。