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:

  1. This guide is comprehensive: you can start with a clean Ubuntu and successfully install OpenCV 2.3.1 by following this guide.
  2. This guide is for OpenCV 2.3.1. The other guides I found used previous versions of OpenCV.
  3. 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.

  1. Remove any installed versions of ffmpeg and x264 by entering the following command:

sudo apt-get remove ffmpeg x264 libx264-dev

  1. 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

  1. 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

  1. Download and install install x264.
    1. Download a recent stable snapshot of x264 fromftp://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.
    2. Configure and build the x264 libraries by entering the following commands:

./configure --enable-shared
make
sudo make install

  1. Download and install install ffmpeg.
    1. Download ffmpeg version 0.8.x fromhttp://ffmpeg.org/download.html. Note: Versions of OpenCV prior to 2.3.1 require ffmpeg 0.7.x.
    2. 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

  1. Download and install gtk by entering the following command:

sudo apt-get install libgtk2.0-0 libgtk2.0-dev

  1. Download and install libjpeg by entering the following command:

sudo apt-get install libjpeg62 libjpeg62-dev

  1. Download and install install v4l (video for linux).
    1. Download v4l-utils-0.8.5.tar.bz2 fromhttp://www.linuxtv.org/downloads/v4l-utils/
    2. Build v4l by entering the following commands in a terminal:

make
sudo make install

  1. Download and install install OpenCV.
    1. Download OpenCV version 2.3.1 fromhttp://sourceforge.net/projects/opencvlibrary/files/
    2. 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 ..

    1. 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.

    1. Run make
    2. Run sudo make install
  1. Configure Linux.
    1. 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!

    2. 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

    3. 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` my_code.cpp  -o my_code `pkg-config opencv --libs` 

 

References

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这是一个用来安装之前下载的支持软件的指南。 首先,确保你已经成功下载了支持软件的安装文件。通常,这个文件的扩展名为.exe或.msi。 接下来,双击打开下载的安装文件。系统可能会弹出安全警告,确认你信任该软件,点击“继续”或“运行”继续进行安装。 安装程序启动后,你会看到一个安装向导的界面。按照向导提供的指示和选项来完成安装过程。 在安装过程中,你可能需要接受许可协议。请阅读协议内容,如果同意,请勾选相应的选项,然后点击“下一步”或“继续”。 接下来,你需要选择软件的安装位置。默认情况下,安装程序会将软件安装到系统的默认文件夹中。如果你想将其安装到其他位置,可以点击“浏览”按钮选择你希望的文件夹,然后点击“下一步”或“安装”。 安装程序会开始压缩和复制文件到你选择的目标文件夹中。这个过程可能需要一些时间,取决于你的计算机性能和软件的大小。 安装完成后,你通常会看到一个安装成功的提示。此时,你可以点击“完成”按钮退出安装程序。 现在,你可以在计算机上找到并启动刚刚安装的支持软件了。通常,你可以在开始菜单、桌面快捷方式或安装文件夹中找到软件的图标。 这个指南的步骤适用于大多数支持软件的安装过程。但请注意,不同软件的安装过程可能略有差异。如果你在安装过程中遇到任何问题,建议你查阅软件的官方文档或联系软件提供商获取帮助。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值