今天安装opencv2.3.0在自己的机器上,因为觉得用脚本执行一系列安装的命令比较方便,所有花了一天的时间初步学习了怎么编写最简单的shell 脚本。
首先安装Opencv2.3.0需要cmake 配合。所以去官网上下载了cmake2.8的源码进行编译安装。
其实安装cmake 的步骤并不复杂,需要先安装g++ 然后在cmake 的目录里面make && make install 。但是今天要使用shell 脚本来执行自动下载和安装就比较麻烦了。附上源代码。
代码本身并作过多的解释,应该很容易看得懂,就是首先下载,然后解压,然后判断当前的系统是否已经安装了g++,之后在编译安装。
不过最要命的问题是在执行shell脚本的时候会出现:unexpected operator.这样的错误。查阅资料后发现了解决的方法,在我的另外一篇文字中http://blog.youkuaiyun.com/bush2582/article/details/20140871
之后,就顺顺利利的搞定了。
#########################################################################
# File Name: Install_cmake.sh
# Author: ma6174
# mail: ma6174@163.com
# Created Time: 2014年02月28日 星期五 13时32分53秒
#########################################################################
#!/bin/bash
##############################################
# FunctionName:echocolor
# Author: bush2582
# Role:the output will have color
# Created Time:
##############################################
echocolor( )
{
echo -e "\e[0;33m${@}\e[0m";
}
##############################################
# FunctionName:InstallGCC
# Author: bush2582
# Role:check g++ is already in system
# Created Time:
##############################################
function InstallGCC ( )
{
which g++;
if [ $? -eq 1 ];
then
read -p " g++ is not installed in this system do you want to install? (Y/y/n/N) " ynInstall_GCC;
if [ $ynInstall_GCC = "Y" ] || [ $ynInstall_GCC = "y" ] ;
then
#echo " now we will install g++ ";
echocolor "now we will install g++"
sudo apt-get install g++;
fi
else
echocolor "g++ already install in this system ";
fi
}
##############################################
# FunctionName:InstallCmake
# Author: bush2582
# Role:install Cmake
# Created Time:
##############################################
function InstallCmake( )
{
InstallGCC;
echocolor " now we will star the program that CMake is installed in this system ";
cd cmake-2.8.0;
./configure;
sudo make;
sudo make install;
exit 0;
}
#########################################################################
read -p "Do you want to download Cmake? (Y/y/n/N)?" downyn
if [ $downyn = "Y" ] || [ $downyn = "y" ];
then
wget http://down1.chinaunix.net/distfiles/cmake-2.8.0.tar.gz;
echocolor "now Staring Tar cmake";
tar -xvf cmake-2.8.0.tar.gz;
else
echocolor "now Staring Tar cmake";
tar -xvf cmake-2.8.0.tar.gz;
fi
read -p " Do you want to install camke now (Y/y/n/N)? " yn
if [ $yn = "y" ] || [ $yn = "Y" ] ;
then
InstallCmake;
else
exit 0;
fi
#######################################################################
# File Name: LoadOpencv.sh
# Author: ma6174
# mail: ma6174@163.com
# Created Time: 2014年02月28日 星期五 10时46分11秒
#########################################################################
#!/bin/bash
#--------------------------------------------#
# FunctionName:echocolor
# Author: bush2582
# Role:the output will have color
# Created Time:
#--------------------------------------------#
echocolor( )
{
echo -e "\e[0;33m${@}\e[0m";
}
read -p "Do you want to download Opencv-2.3.0? (Y/N)" DownLoadOpencv
if [ $DownLoadOpencv = "Y" ];
then
echocolor "now Staring downLoad Opencv2.3.0 ";
wget http://nchc.dl.sourceforge.net/project/opencvlibrary/opencv-unix/2.3/OpenCV-2.3.0.tar.bz2;
echocolor "Staring tar OpenCV-2.3.0.tar.bz2 "
tar -xvf OpenCV-2.3.0.tar.bz2
else
tar -xvf OpenCV-2.3.0.tar.bz2
echocolor "Staring tar OpenCV-2.3.0.tar.bz2 "
fi
cd OpenCV-2.3.0
sudo mkdir relese
cd relese
read -p "Please input Dir which you want to install " Dir
sudo cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=$Dir -D BUILD_PYTHON_SUPPORT=ON ..
read -p "now we will star opencv make&&install in $Dir .Do you want to continue?( Y/N ) " GoOn
if [ $GoOn = "Y" ] ;
then
sudo make
sudo make install
else
exit 0;
fi