美文网首页
2020-07-03 实验内opencv编译脚本,一键安装

2020-07-03 实验内opencv编译脚本,一键安装

作者: Joyner2018 | 来源:发表于2020-07-03 16:06 被阅读0次
#!/bin/bash
if [ ! -d /usr/local/cuda-8.0 ] ; then
        echo "Please install cuda8.0."
        exit
else
    if [[ ${PATH} == */usr/local/cuda-8.0* ]]; then
        echo ${PATH}
    else
        export PATH=/usr/local/cuda-8.0:$PATH
        echo "export PATH=$PATH" >> ~/.bashrc
    fi
fi

if [ ! -d ~/.local/lib/python2.7/site-packages/numpy ]; then
    wget ftp://192.168.9.5:2121/whl_and_run/numpy-1.14.2-cp27-cp27mu-manylinux1_x86_64.whl 
    pip2 install numpy-1.14.2-cp27-cp27mu-manylinux1_x86_64.whl --user
fi

PYTHON_DIR=$(which python2)
work_dir=$(pwd)
packdir=${work_dir}/package
installdir=${work_dir}/opencv
if [ ! -d ${packdir} ] ; then
    mkdir -p ${packdir}
fi
if [ -d ${installdir} ]; then
    rm -rf ${installdir}/*
else
    mkdir -p ${installdir}
fi

if [ -f ${work_dir}/software/auto_install_opencv_dlib_by_sudo.sh ]; then rm ${work_dir}/software/auto_install_opencv_dlib_by_sudo.sh ; iif [ -f ${work_dir}/software/auto_install_opencv_dlib_by_sudo.sh ]; then rm ${work_dir}/software/auto_install_opencv_dlib_by_sudo.sh ; fi
wget ftp://192.168.9.5:2121/software/auto_install_opencv_dlib_by_sudo.sh

## Download the Opencv installation package
cd ${packdir}
if [ -f ${packdir}/opencv-2.4.13.6.zip ] ; then
        rm ${packdir}/opencv-2.4.13.6.zip
        rm -rf ${packdir}/opencv-2.4.13.6
fi
wget ftp://192.168.9.5:2121/software/opencv-2.4.13.6.zip -O opencv-2.4.13.6.zip
unzip opencv-2.4.13.6.zip
cd opencv-2.4.13.6


## 192.168.1.1 bug
rm ${packdir}/opencv-2.4.13.6/modules/highgui/src/cap_ffmpeg_impl.hpp
wget ftp://192.168.9.5:2121/software/cap_ffmpeg_impl.hpp -O ${packdir}/opencv-2.4.13.6/modules/highgui/src/cap_ffmpeg_impl.hpp

## Compile the opencv
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=DEBUG -D CMAKE_INSTALL_PREFIX=${installdir} -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_PYTHON_SUPPORT=ON -D PYTHON_EXECUTABLE=${PYTHON_DIR} -D WITH_CUDA=ON ..
make -j12
make install

## Test whether the cv2.so file was generated.
cv2_dir=${installdir}/lib/python2.7/dist-packages
cv2_path=${installdir}/lib/python2.7/dist-packages/cv2.so
if [ ! -f ${cv2_path} ] ; then
        echo "[ERROR] No cv2.so file was generated."
else
        echo "[INFO] The cv2.so file has been generated ${cv2_dir}"
fi

## Add the path to cv2.so to the bashrc file
if [[ ${PYTHONPATH} == *{cv2_dir}* ]]; then
    echo ${PYTHONPATH}
else
    echo "export PYTHONPATH=${cv2_dir}:$PYTHONPATH" >> ~/.bashrc
fi

## Test whether Opencv was installed successfully.
echo "opencv version"
export PATH=/usr/local/cuda-8.0:$PATH
export PYTHONPATH=${cv2_dir}:$PYTHONPATH
python2 -c 'import cv2;print cv2.__version__'

相关文章

网友评论

      本文标题:2020-07-03 实验内opencv编译脚本,一键安装

      本文链接:https://www.haomeiwen.com/subject/cnisqktx.html