# /bin/bash
# sli
# 2017-3-29 16:00
# 编译配置
# 路径均应当使用!!绝对路径!!
# Should use absolute path!
# -----------------------------------------------------------
# OpenCV 源码路径
# OpenCV source path
OPENCV_DIR=/home/sli/Python/lib_install/opencv-py3/opencv
# Python 解析器路径
# Python interp path
PYTHON_HOME=/home/sli/Python/env/tensorflow
# Python 版本号
# Python version
PYTHON_VER=3.6
# Python 链接库路径
# Python link library path (.a or .so file path)
PYTHON_LIB=/home/sli/Python/py36/lib/libpython3.6m.a
# ------------------------------------------------------------
# 开始下载依赖、源码,并配置、编译、安装
sudo apt install build-essential cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
# Optional, but installing these will ensure you have the latest versions compiled with OpenCV
sudo apt install libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
if [ ! -d "$OPENCV_DIR" ]
then
git clone https://github.com/opencv/opencv "$OPENCV_DIR"
fi
cmake \-D CMAKE_BUILD_TYPE=RELEASE \-D BUILD_TIFF=ON \-D BUILD_opencv_java=OFF \-D WITH_CUDA=OFF \-D ENABLE_AVX=ON \-D WITH_OPENGL=ON \-D WITH_OPENCL=ON \-D WITH_IPP=OFF \-D WITH_TBB=ON \-D WITH_EIGEN=ON \-D WITH_V4L=ON \-D WITH_VTK=OFF \-D BUILD_TESTS=OFF \-D BUILD_PERF_TESTS=OFF \-D BUILD_opencv_python2=OFF \-D BUILD_opencv_python3=ON \-D CMAKE_INSTALL_PREFIX=${OPENCV_DIR}/release \-D PYTHON_DEFAULT_EXECUTABLE=$PYTHON_HOME/bin/python${PYTHON_VER} \-D PYTHON3_EXECUTABLE=$PYTHON_HOME/bin/python${PYTHON_VER} \-D PYTHON3_LIBRARY=$PYTHON_LIB \-D PYTHON_INCLUDE_DIR=$PYTHON_HOME/include/python${PYTHON_VER}m \-D PYTHON3_NUMPY_INCLUDE_DIRS=$PYTHON_HOME/lib/python${PYTHON_VER}/site-packages/numpy/core/include/ \"$OPENCV_DIR"
# 检查cmake的输出
# 注意Python解析器是否指定正确
# At this point, take a look at the console output.
# OpenCV will print a report of modules and features that it can and can't support based on your system and installed libraries.
# The key here is to make sure it's not missing anything you'll need!
# If something's missing, then you'll need to install those dependencies and rerun the cmake command.
make -j$(nproc) && make install
# 编译可能需要一段时间
# This will also take a while...
# 部署到之前指定的Python解析器目录下
ln -s ${OPENCV_DIR}/release/lib/python${PYTHON_VER}/site-packages/cv2.* ${PYTHON_HOME}/lib/python${PYTHON_VER}/site-packages/