1. 源码安装opencv.
OpenCV-2.4.9, 自动识别python2.7
cd opencv-2.4.9
mkdir build
cd build
或者opencv3.4.0
直接pip install -U opencv_python-3.4.1.15-cp36-cp36m-manylinux1_x86_64 也是可以的.
-D WITH_CUDA=OFF \
-D WITH_1394=OFF \
-D CMAKE_BUILD_TYPE=RELEASE \
-D BUILD_opencv_python2=ON \
-D BUILD_opencv_python3=ON \
-D BUILD_opencv_java=OFF \
-D WITH_FFMPEG=OFF \
-D WITH_GSTREAMER=OFF \
-D LAPACK_IMPL=OpenBLAS \
-D LAPACK_LIBRARIES=/opt/OpenBLAS/lib/libopenblas.so \
-D WITH_TBB=OFF \
-D CMAKE_INSTALL_PREFIX=/home/ly/OpenCV ..
make -j8
make install -j8
export PKG_CONFIG_PATH=/home/ly/OpenCV/lib/pkgconfig/:$PKG_CONFIG_PATH
export LD_LIBRARY_PATH=/home/ly/OpenCV/lib/:$LD_LIBRARY_PATH
export PATH=$HOME/OpenCV/include:$PATH
export C_INCLUDE_PATH=$HOME/OpenCV/include:$C_INCLUDE_PATH
export CPLUS_INCLUDE_PATH=$HOME/OpenCV/include:$CPLUS_INCLUDE_PATH
g++ `pkg-config opencv --cflags --libs opencv` test.cpp # 成功. 2.4.9版本可以!
不能这样运行了!!
g++ `pkg-config --cflags opencv` test.cpp `pkg-config --libs opencv` # 分开使用!
安装mxnet时, 修改config.mk, 不再将OpenCV添加至ADD_CFLAGS和ADD_LDFLAGS, 因为在Makefile中, 会利用pkg-config --cflags opencv和pkg-config --libs opencv读取OpenCV的include和lib路径. 避免和58的opencv3版本出现不兼容的情况.
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=OFF -D WITH_CUDA=ON -D WITH_V4L=OFF -D WITH_QT=OFF -D WITH_OPENGL=OFF ..
使用CUDA, 编译速度太慢了!