下面是复制自官方的安装文档,我在ubuntu13.04上编译安装OpenCV2.4.5安装成功。先到opencv论坛上下载linux版本的源码。然后按照下面的提示安装就可以了。
刚开始的时候我没有按照下面的方法安装,而是直接安装cmake-qt后直接编译安装,结果不成功。
第二次严格按照下面的安装步骤成功了,并且配置好了codeblocks IDE。
OpenCV installation for Ubuntu 12.04
To install OpenCV 2.4.2 or 2.4.3 on the Ubuntu 12.04 operating system, first install a developer environment to build OpenCV.
sudo apt-get -y install build-essential cmake pkg-config
#这一步是安装必要的编译环境,gcc,g++,gdb等,以及cmake工具,pkg-config管理包。一般ubuntu管理包已经安装好了,只是查看更新一下而已。
Install Image I/O libraries
sudo apt-get -y install libjpeg62-dev
sudo apt-get -y install libtiff4-dev libjasper-dev
#安装图像接口。第二步会替代第一步安装的,可以只安装第二步。
Install the GTK dev library
sudo apt-get -y install libgtk2.0-dev
#安装GTK,这一步很重要。
Install Video I/O libraries
sudo apt-get -y install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
#安装视频接口库,处理视频必备,最好安上。
#下面都是可选的,我都没有安,直接跳过了。
Optional - install support for Firewire video cameras
sudo apt-get -y install libdc1394-22-dev
Optional - install video streaming libraries
sudo apt-get -y install libxine-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev
Optional - install the Python development environment and the Python Numerical library
sudo apt-get -y install python-dev python-numpy
Optional - install the parallel code processing library (the Intel tbb library)
sudo apt-get -y install libtbb-dev
Optional - install the Qt dev library
sudo apt-get -y install libqt4-dev
Now download OpenCV 2.4 to wherever you want to compile the source.
mkdir xxx
cd xxx
wget http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.2/Op...
or
wget http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.3/Op...
#上面是在线下载的,我还是用离线下载的。这步跳过。
tar -xvf OpenCV-2.4.*.tar.bz2
#解压opencv源代码。
Create and build directory and onfigure OpenCV with cmake. Don't forget the .. part at the end of cmake cmd !!
cd OpenCV-2.4.*
mkdir build
cd build
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_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON ..
#配置cmake选项,全部输入命令行就好了,别忘了最后的两个点。
#下面是编译和安装,不多说,都懂的。
Now compile it
make
And finally install OpenCV
sudo make install
Tags:
OpenCV
Ubuntu
installation
附注:
命令行下编译opencv的程序
g++ DisplayImage.cpp -o DisplayImage `pkg-config opencv --cflags --libs`
运行程序
./DisplayImage abc.jpg