Ubuntu(12.04 LTS) 装opencv2.4.1
来源:互联网 发布:怎么统计淘宝消费 编辑:程序博客网 时间:2024/06/05 21:49
之前基本都算在windows 的vc++6.0 用opencv1.0,学些图像的基本处理,现在转战Ubuntu,先装个新版本的Opencv...转大神
The latest Long Term Support version of Ubuntu(12.04 LTS) is out and a new version of OpenCV was released as well. This means that now is a great opportunity to update my OpenCV installation guide to the latest versions, Ubuntu 12.04 LTS and OpenCV 2.4.1.
We are going to setup OpenCV to use the new Qt highgui interface, which is much better than the simple highgui interface. Also, we will install OpenCV with support for OpenGL, as well as reading and writing videos, access to a webcam, Python, C and C++ interfaces, and Intel Threading Building Blocks (TBB).
OK, so the first step is to make sure that everything in the system is updated and upgraded:
1
sudo
apt-get update
2
sudo
apt-get upgrade
Now, you need to install many dependencies, such as support for reading and writing image files, drawing on the screen, some needed tools, etc… This step is very easy, you only need to write the following command in the Terminal:
1
sudo
apt-get
install
build-essential libgtk2.0-dev libjpeg-dev libtiff4-dev libjasper-dev libopenexr-dev cmake python-dev python-numpy python-tk libtbb-dev libeigen2-dev yasm libfaac-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev libx264-dev libqt4-dev libqt4-opengl-dev sphinx-common texlive-latex-extra libv4l-dev libdc1394-22-dev libavcodec-dev libavformat-dev libswscale-dev
Time to get the OpenCV 2.4.1 source code:
1
cd
~
2
wget http://downloads.sourceforge.net/project/opencvlibrary/opencv-unix/2.4.1/OpenCV-2.4.1.
tar
.bz2
3
tar
-xvf OpenCV-2.4.1.
tar
.bz2
4
cd
OpenCV-2.4.1
Now we have to generate the Makefile by using cmake. In here we can define which parts of OpenCV we want to compile. Since we want to use Python, TBB, OpenGL, Qt, work with videos, etc, here is where we need to set that. Just execute the following line at the terminal to create the appropriate Makefile. Note that there are two dots at the end of the line, it is an argument for the cmake program and it means the parent directory (because we are inside the build directory, and we want to refer to the OpenCV directory, which is its parent).
1
mkdir
build
2
cd
build
3
cmake -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 ..
Check that the above command produces no error and that in particular it reports FFMPEG as YES. If this is not the case you will not be able to read or write videos. Also, check that Python, TBB, OpenGL, V4L, OpenGL and Qt are detected.
If anything is wrong, go back, correct the errors by maybe installing extra packages and then run cmake again. You should see something similar to this:
Now, you are ready to compile and install OpenCV 2.4.1:
1
make
2
sudo
make
install
Now you have to configure OpenCV. First, open the opencv.conf file with the following code:
1
sudo
gedit /etc/ld.so.conf.d/opencv.conf
Add the following line at the end of the file(it may be an empty file, that is ok) and then save it:
1
/usr/
local
/lib
Run the following code to configure the library:
1
sudo
ldconfig
Now you have to open another file:
1
sudo
gedit /etc/
bash
.bashrc
Add these two lines at the end of the file and save it:
1
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/
local
/lib/pkgconfig
2
export
PKG_CONFIG_PATH
Finally, close the console and open a new one, restart the computer or logout and then login again. OpenCV will not work correctly until you do this.
Now you have OpenCV 2.4.1 installed in your computer with Python, TBB, OpenGL, video, and Qt support.
Check out the cool Qt interface which provides image viewing capabilities with zoom, as well as the ability to save the current image with just one click.
If you zoom in enough, you can see the RGB (or intensity) values for each pixel.
Now let’s build some samples included in OpenCV:
1
cd
~/OpenCV-2.4.1/samples/c
2
chmod
+x build_all.sh
3
./build_all.sh
Now we are ready to run the examples:
1
./facedetect --cascade=
"/usr/local/share/OpenCV/haarcascades/haarcascade_frontalface_alt.xml"
--scale=1.5 lena.jpg
1
./facedetect --cascade=
"/usr/local/share/OpenCV/haarcascades/haarcascade_frontalface_alt.xml"
--nested-cascade=
"/usr/local/share/OpenCV/haarcascades/haarcascade_eye.xml"
--scale=1.5 lena.jpg
1
~/OpenCV-2.4.1/build/bin/grabcut ~/OpenCV-2.4.1/samples/cpp/lena.jpg
1
~/OpenCV-2.4.1/build/bin/calibration_artificial
1
python ~/OpenCV-2.4.1/samples/python2/turing.py
- Ubuntu(12.04 LTS) 装opencv2.4.1
- Ubuntu 14.04 LTS 安装 OpenCV2.4.12
- Install Opencv2.4.9 on Ubuntu 16.04 LTS
- OOAD作业--ubuntu 12.04LTS 64bit编译安装Opencv2.4.3
- 装系统:Win7+Ubuntu 12.04 LTS
- ubuntu 12.04 LTS 发布
- ubuntu 12.04 LTS-历史记录
- ubuntu 12.04 LTS 版本
- Ubuntu 12.04.2 LTS
- ubuntu 12.04 opencv2.0
- ubuntu 12.04 LTS MD5校验码
- Ubuntu 12.04 LTS 的安装
- ubuntu 12.04 lts 驱动例子
- Ubuntu 12.04 LTS配置指南
- Ubuntu 12.04 LTS 安装JDK
- Ubuntu 12.04 LTS更炫更具吸引力
- Ubuntu 12.04 LTS 更新源
- ubuntu 12.04 lts 源问题
- hdu 4800 Josephina and RPG dp
- emacs 学习笔记 - 基本编辑
- canvas绘制时钟
- HDU 3652——B-number(数位DP)
- redhat yum源安装与配置
- Ubuntu(12.04 LTS) 装opencv2.4.1
- 黑马程序员-探究字节流四(应用文件切割合并)
- Windows 7 下设置 Beagle Bone Black 通过USB网络适配器访问Internet --Derek Molloy 的视频教程
- 安装conkeror--emacs风格的web浏览器
- call()方法和属性的继承
- canvas动画效果
- JAVA i=i++的问题
- Emacs学习笔记(5):更有效率的编辑
- 黑马程序员-探究字节流五(其他流)