歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Ubuntu 11.10下安裝配置OpenCV 2.3.1

Ubuntu 11.10下安裝配置OpenCV 2.3.1

日期:2017/2/28 15:55:25   编辑:Linux教程

這篇應該就是最新(2012/3/3)的關於在Ubuntu 11.10下安裝配置OpenCV 2.3.1了向導了。寫的很詳細。
我用這個向導配置了,但是有幾個問題,解決辦法貼在後面。

A Comprehensive Guide to Installing and Configuring OpenCV 2.3.1 on Ubuntu

This guide describes how to install and configure OpenCV 2.3.1 and its dependencies on Ubuntu. It is a compilation of my notes recorded during dozens of OpenCV installs on several different systems. This guide differs from other OpenCV guides in the following ways:

This guide is comprehensive: you can start with a clean Ubuntu and successfully install OpenCV 2.3.1 by following this guide.
This guide is for OpenCV 2.3.1. The other guides I found used previous versions of OpenCV.
This guide includes all of the steps you need to use a webcam with OpenCV.
Credit and thanks go to FakeOutdoorsman and Sebastian Montabone for their excellent posts, upon which several of the steps in this guide are based.

If you need help troubleshooting OpenCV installation problems, see the companion guide “A Comprehensive OpenCV Installation Troubleshooting Guide.”

The Installation Procedure
To install and configure OpenCV 2.3.1, complete the following steps.

Remove any installed versions of ffmpeg and x264 by entering the following command:
sudo apt-get remove ffmpeg x264 libx264-dev

Get all the dependencies for x264 and ffmpeg by entering the following commands:
sudo apt-get update
sudo apt-get install build-essential checkinstall git cmake libfaac-dev libjack-jackd2-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libsdl1.2-dev libtheora-dev libva-dev libvdpau-dev libvorbis-dev libx11-dev libxfixes-dev libxvidcore-dev texi2html yasm zlib1g-dev

Download and install gstreamer by entering the following command:
sudo apt-get install libgstreamer0.10-0 libgstreamer0.10-dev gstreamer0.10-tools gstreamer0.10-plugins-base libgstreamer-plugins-base0.10-dev gstreamer0.10-plugins-good gstreamer0.10-plugins-ugly gstreamer0.10-plugins-bad gstreamer0.10-ffmpeg

Download and install install x264.

Download a recent stable snapshot of x264 from ftp://ftp.videolan.org/pub/videolan/x264/snapshots/. The exact version does not seem to matter. To write this guide, I used version x264-snapshot-20110808-2245-stable.tar.bz2, but I have used previous versions too.
Configure and build the x264 libraries by entering the following commands:
./configure --enable-static
make
sudo make install

Download and install install ffmpeg.

Download ffmpeg version 0.8.x from http://ffmpeg.org/download.html. Note: Versions of OpenCV prior to 2.3.1 require ffmpeg 0.7.x.
Configure and build ffmpeg by entering the following commands in a terminal:
./configure --enable-gpl --enable-libfaac --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libxvid --enable-nonfree --enable-postproc --enable-version3 --enable-x11grab
make
sudo make install

Download and install gtk by entering the following command:
sudo apt-get install libgtk2.0-0 libgtk2.0-dev

Download and install libjpeg by entering the following command:
sudo apt-get install libjpeg62 libjpeg62-dev

Download and install install v4l (video for linux).

Download v4l-utils-0.8.5.tar.bz2 from http://www.linuxtv.org/downloads/v4l-utils/
Build v4l by entering the following commands in a terminal:
make
sudo make install

Download and install install OpenCV.

Download OpenCV version 2.3.1 from http://sourceforge.net/projects/opencvlibrary/files/
Use the following command to untar the source files
tar xvf OpenCV-2.3.1.tar.bz2
cd OpenCV-2.3.1/
mkdir build
cd build
cmake ..

Check that the output of cmake includes the following text:

found gstreamer-base-0.10
GTK+ 2.x: YES
FFMPEG: YES
GStreamer: YES
V4L/V4L2: Using libv4l
Note: In versions of OpenCV prior to 2.3.1, the binary digit 1 was used instead of the word YES, like this: FFMPEG: 1.

Run make
Run sudo make install
Configure Linux.

Tell linux where the shared libraries for OpenCV are located by entering the following shell command:

export LD_LIBRARY_PATH=/usr/local/lib

Add the command to your .bashrc file so that you don’t have to enter every time your start a new terminal.

Alternatively, you can configure the system wide library search path. Using your favorite editor, add a single line containing the text /usr/local/lib to the end of a file named /etc/ld.so.conf.d/opencv.conf. Using vi, for example, enter the following commands:

sudo vi /etc/ld.so.conf.d/opencv.conf
G
o
/usr/local/lib
<Esc>
:wq!

Using your favorite editor, add the following two lines to the end of /etc/bash.bashrc:

PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH

Reboot.
After completing the previous steps, your system should be ready to compile code that uses the OpenCV libraries. The following example shows one way to compile code for OpenCV:

g++ `pkg-config opencv --cflags` `pkg-config opencv --libs` my_code.cpp -o my_code

-----------------------------------分割線----------------------------------
1.我make完opencv的時候,老是提示:

make[2]: *** [lib/libopencv_highgui.so.2.3.1] Error 1

make[1]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/all] Error 2

看原向導下面的評論,說./configure ffmpeg和x264的時候,除了向導裡面提到的那些--enable-xxx之類的,還要加上--enable-pic --enable-shared。據說就能解決了,但是我的還是解決不了。

我問題出在ffmpeg上面,按照它的方法直接從ppa上git安裝文件的話是不行的,因為這樣git過來的ffmpeg版本太高了,而Ubuntu 11.10跟opencv2.3.1貌似只要0.8.x版本的。你可以官網上自己下壓縮文件,ffmpeg-0.8.10.tar.bz2 下載:

免費下載地址在 http://linux.linuxidc.com/

用戶名與密碼都是www.linuxidc.com

具體下載目錄在 /2012年資料/3月/3/Ubuntu 11.10下安裝配置OpenCV 2.3.1/

再解壓,按照它的方法來。

2.假如你裝錯了ffmpeg,想卸載的時候,可能會遇到因為配置文件沒刪干淨卸載不了的問題,這個按照下面的方法來:

在終端中執行 sudo synaptic,以便啟動 Synaptic 包管理工具。

點擊 Synaptic 右下角的 Status 按鈕進行切換。

現在,你應該能夠在 Synaptic 的左邊看到 Not installed (residual config)。選擇它即可在右邊看到包含有殘余配置文件的包,你可以在此選擇刪除該包。


3.向導的第十步:Configure Linux 的第一步,注意G o應該是vi的指令,要是你用vim的話,是不需要G o的。直接按i進入編輯模式,加入/usr/local/lib就可以了。

Copyright © Linux教程網 All Rights Reserved