ubuntu下安装opencv2.4.13成功版

本文参考相关链接: http://blog.csdn.net/honyniu/article/details/46390097
 
系 统:Ubuntu 14.04 x64
opencv版本:2.4.13
 
安装之前,系统已经安装好cuda7.5和cudnn V4
 
安装相关依赖项:
 
 sudo apt-get install build-essential
 sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec- dev libavformat-dev libswscale-dev
 sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
 sudo apt-get install libatlas-base-dev gfortran

 

 
配置opencv,在这里使用cmake-gui进行配置,,后面会介绍。
 
先安装cmake-gui,直接在终端输入cmake-gui会有提示的:
sudo apt-get install cmake-qt-gui
 
把下载好的opencv2-4-13-source放在download下,,解压这个文件,在解压后的文件夹下新建一个opencv-debug文件夹:
  ubuntu下安装opencv2.4.13成功版_第1张图片
 
 
从终端cd 到opencv2-4-13-debug下,执行:cmake-gui :
 
点击configure出现下面的界面
  ubuntu下安装opencv2.4.13成功版_第2张图片
 
cmake中configure的作用就是能够读出系统已经安装的相关文件,然后进行generate:
 然后关闭后会进行安装。
编译安装,还是在刚刚的cd的那个文件夹opencv2-4-13-debug下执行:
make -j8
sudo make install
这样就安装成功了。
 
安装成功后还需要设置opencv的环境变量
打开文件
sudo gedit /etc/profile

 

在文件最后添加
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH

 

执行下列命令, 使环境变量立即生效
source /etc/profile

 

lib库路径
打开文件
sudo gedit /etc/ld.so.conf.d/opencv.conf

 

opencv的库一般安装在’/usr/local/lib’文件夹下,在文件内添加
/usr/local/lib

 

执行下列命令使之立刻生效
sudo ldconfig

 

经过上面的流程,这样就可以在eclipse里或者qtcreator里用opencv了。 不过要配置号相应的路径和lib文件。
 
python下查看opencv版本信息:
ubuntu下安装opencv2.4.13成功版_第3张图片
 
示例代码
对opencv的sample进行编译并运行
cd opencv2-4-13-source/samples/c
./build_all.sh
./facedetect --cascade="/usr/local/share/OpenCV/haarcascades/haarcascade_frontalface_alt.xml" --scale=1.5 lena.jpg 
 
终端显示:
  ubuntu下安装opencv2.4.13成功版_第4张图片
结果显示:
  ubuntu下安装opencv2.4.13成功版_第5张图片
 
 
另外youtube有一个安装脚本,保存为opencv2-4-13.sh (没有尝试过能否安装成功)
 
复制代码
version="3.1.0"
cd opencv-$version
 
echo "Installing OpenCV" $version
 
echo "Removing any pre-installed ffmpeg and x264"
echo "sudo apt-get remove x264 libx264-dev"
echo "*********************************"
 
echo "Installing Dependenices"
sudo apt-get install libopencv-dev
 
echo "***********Build Tools**********************"
 
echo "<---------------------------------------------------Build Tools------------------------------------------------>"
sudo apt-get install build-essential checkinstall cmake pkg-config
echo "*************_*"
 
 
echo "<-----------------------------------------------------Image I/O---------------------------------------------------->"
sudo apt-get install libtiff5-dev libjpeg-dev libjasper-dev libpng-dev zliblg-dev libwebp-dev libopenexr-dev libgdal-dev
echo "*********************************"
 
echo "<-------------------------------------------------------Video I/O-------------------------------------------------->"
sudo apt-get install libavcodec-dev libavformat-dev libmp3lame-dev libswscale-dev libdc1394-22-dev libxine-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev v4l-utils libfaac-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev libx264-dev x264 yasm
echo "*********************************"
 
echo "Parallelism and linear algebra libraries"
sudo apt-get install libtbb-dev libeigen3-dev
echo "*********************************"
 
echo "<-----------------------------------------------for GUI------------------------------------------------>"
sudo apt-get install libqt4-dev libgtk2.0-dev qt5-default
echo " sudo apt-get install libvtk6-dev"
 
echo "***********************************************************************************************************"
 
echo "<-------------For JAVA------------------->"
echo "sudo apt-get install ant default-jdk"
 
echo "<-----******-----For Python-----******------>"
echo "sudo apt-get install python-dev python-tk python-numpy python3-dev python3-tk python3-numpy python-matplotlib
sudo apt-get install python-opencv"
 
echo "%%%%%%%%%%%%%%%%%%%%%_%"
mkdir build
cd build
echo "*******************_"
 
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_DOCS=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON -D WITH_EIGEN=ON -D FORCE_VTK=TRUE -D WITH_VTK=ON ..
 
echo "cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -DOPENCV_EXTRA_MODULES_PATH=opencv_contrib-master/modules/ -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_DOCS=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON -D WITH_EIGEN=ON -D FORCE_VTK=TRUE -D WITH_VTK=ON .."
 
make -j4
 
echo "*********************************"
 
sudo make install
 
echo "*********************************"
 
sudo sh -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf'
 
echo "*********************************"
 
sudo ldconfig
 
echo "OpenCV" $version "ready to be used"
复制代码

 

你可能感兴趣的:(ubuntu)