Ubuntu 安装 opencv 2.0

Installing OpenCV 2.0 in Ubuntu

OpenCV is an excellent library for Computer Vision. I have been using it for years and it helped me a lot during my master thesis.

OpenCV 1.0 can be easily installed in Ubuntu via the repositories. Unfortunately, the newer version of OpenCV, 2.0, which is full of new features is not yet available in the repositories of Ubuntu.

Here are the steps that I used to successfully install OpenCV 2.0 in Ubuntu 9.10. I have used this procedure for previous versions of Ubuntu as well with minor modifications (if any).

First, you need to install many dependencies, such as support for reading and writing jpg files, movies, 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 libavcodec-dev libavformat-dev libjpeg62-dev libtiff4-dev cmake libswscale-dev libjasper-dev

The next step is to get the OpenCV 2.0 code:

1 cd ~
3 tar -xvf OpenCV-2.0.0.tar.bz2
4 cd OpenCV-2.0.0

Now, you need to configure how you want to compile OpenCV 2.0. In my case I used /usr/local as the installation directory and I also activated the video support for reading and writing videos using OpenCV (via ffmpeg).

1 ./configure --prefix=/usr/local --enable-apps --enable-shared --with-ffmpeg --with-gnu-ld --with-x --without-quicktime CXXFLAGS=-fno-strict-aliasing

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.

Now, you are ready to compile and install OpenCV 2.0:

1 make
2 sudo make install

Now you have to configure the library. 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, open a new console, restart the computer or logout and then login again. OpenCV will not work correctly until you do this.

Now you have OpenCV 2.0 installed in your computer.

Let’s check some demos included in OpenCV:

1 cd ~
2 mkdir openCV_samples
3 cp /usr/local/share/opencv/samples/c/* openCV_samples
4 cd openCV_samples/
5 chmod +x build_all.sh
6 ./build_all.sh

All the training data for object detection is stored in /usr/local/share/opencv/haarcascades. You need to tell OpenCV which training data to use. I will use one of the frontal face detectors available. Let’s find a face:

1 ./facedetect --cascade="/usr/local/share/opencv/haarcascades/haarcascade_frontalface_alt.xml"--scale=1.5 lena.jpg

Note the scale parameter. It allows you to increase or decrease the size of the smallest object found in the image (faces in this case). Smaller numbers allows OpenCV to find smaller faces, which may lead to increasing the number of false detections. Also, the computation time needed gets larger when searching for smaller objects.

Now let’s see some background subtraction from a video. The original video shows a hand moving in front of some trees. OpenCV allows you to separate the foreground (hand) from the background (trees).

1 ./bgfg_segm tree.avi

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值