1. 程式人生 > >SLAM環境配置--一鍵安裝Opencv2.4指令碼

SLAM環境配置--一鍵安裝Opencv2.4指令碼

直接執行 sh opencv_install.sh 即可成功安裝opencv2

#!/bin/bash

sysInstall='apt-get'
echo "安裝unzip" 
sudo apt-get --yes --force-yes install unzip 
echo "安裝cmake" 
sudo  apt-get --yes --force-yes install cmake 
echo "安裝build-essential" 
sudo  apt-get --yes --force-yes install build-essential
echo "安裝gcc-c++" 
sudo  apt-get --yes --force-yes install gcc-c++
echo "安裝gcc" 
sudo  apt-get --yes --force-yes  install gcc
echo "安裝gtk+-devel" 
sudo apt-get --yes --force-yes install gtk+-devel
echo "安裝gimp-devel" 
sudo apt-get --yes --force-yes install gimp-devel
echo "安裝gimp-devel-tools" 
sudo apt-get --yes --force-yes install gimp-devel-tools
sudo  apt-get --yes --force-yes install zlib-devel
sudo  apt-get --yes --force-yes install gimp-help-browser
sudo  apt-get --yes --force-yes  install libtiff-devel
sudo  apt-get --yes --force-yes install libjpeg-devel
sudo  apt-get --yes --force-yes install libpng-devel
sudo  apt-get --yes --force-yes  install gstreamer-devel
sudo  apt-get --yes --force-yes  install libavc1394-devel
sudo  apt-get --yes --force-yes  install jasper-devel
sudo  apt-get --yes --force-yes  install swig
sudo  apt-get --yes --force-yes install libtool
sudo  apt-get --yes --force-yes  install nasm
sudo  apt-get --yes --force-yes  install libgtk2.0-dev
sudo  apt-get --yes --force-yes  install libavcodec-dev
sudo  apt-get --yes --force-yes  install libavformat-dev
sudo  apt-get --yes --force-yes  install libjpeg62-dev
sudo  apt-get --yes --force-yes  install libtiff4-dev
sudo  apt-get --yes --force-yes  install libswscale-dev
sudo  apt-get --yes --force-yes  install libjasper-dev
#sudo --force-yes  $sysInstall install git 
sudo  apt-get --yes --force-yes  install pkg-config 
sudo  apt-get --yes --force-yes install ibavcodec-dev 
sudo  apt-get --yes --force-yes  install libavformat-dev 
sudo  apt-get --yes --force-yes install libswscale-dev 
sudo  apt-get --yes --force-yes install libtbb2 
sudo  apt-get --yes --force-yes  install libtbb-dev
#用攝像頭才需要安裝
sudo  apt-get --yes --force-yes  install libv4l-dev
sudo  apt-get --yes --force-yes  install v4l2ucp
sudo  apt-get --yes --force-yes  install v4l-utils
#!/bin/bash
cd ~

sudo apt-get --yes --force-yes install build-essential cmake libgtk2.0-dev pkg-config python-dev python-numpy libavcodec-dev libavformat-dev libswscale-dev  

echo "檢查當前路徑下是否有opencv壓縮包,沒有的話需要下載" 
if [ -s 2.4.11.zip ]; then
echo "2.4.11.zip [found]"
else
echo "Error: 2.4.11.zip not found!!!download now......"
wget -c https://github.com/opencv/opencv/archive/2.4.11.zip
fi
echo "解壓縮2.4.11.zip" 
unzip 2.4.11.zip 
cd opencv-2.4.11  
mkdir build
cd build
echo "cmake當前工程"
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
echo "make當前工程" 
#4執行緒這個看自己電腦配置
make j4
echo "sudo make install"  
sudo make install

echo "對opencv進行配置" 
echo '/usr/local/lib'>>/etc/ld.so.conf.d/opencv.conf
sudo ldconfig

echo "對環境變數進行配置"
echo 'PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig'>>/etc/bash.bashrc
echo 'export PKG_CONFIG_PATH'>>/etc/bash.bashrc
source /etc/bash.bashrc

echo "測試一個簡單的程式" 
cd ../samples/c
sudo ./build_all.sh
sudo ./facedetect --cascade="/usr/local/share/OpenCV/haarcascades/haarcascade_frontalface_alt.xml" --scale=1.5 lena.jpg
cd ../../..