Installing OpenCV 2.4.1 in Ubuntu 12.04 LTS

Source: Internet
Author: User

Transfer from http://www.samontab.com/web/2012/06/installing-opencv-2-4-1-ubuntu-12-04-lts/

EDIT: I published a new guide using Ubuntu 14.04 LTS and OpenCV 2.4.9 here.

The latest Long term support version of Ubuntu (12.04 LTS) are out and a new version of OpenCV were released as well. This means a great opportunity to update my OpenCV installation Guide to the latest versions, Ubuntu 12.04 LTS and OpenCV 2.4.9.

We are going to setup OpenCV to use the new Qt Highgui interface, which was much better than the simple Highgui interface. Also, we'll 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 was to make sure. Everything in the system is updated and upgraded:

sudo apt-get  updatesudo apt-get Upgrade

Now, you need to install many dependencies, such as support for reading and writing image files, drawing on the screens, so Me needed tools, etc ... This step was very easy and you have need to write the following command in the Terminal:

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-  -dev Libavcodec-dev Libavformat-dev Libswscale-dev

Download opencv2.4.9

TAR-XJVF opencv-2.4. 9. tar.bz2   cd opencv-2.4.  9    

Now we had to generate the Makefile by using CMake. In this we can define which parts of OpenCV we want to compile. Since we want to the use of Python, TBB, OpenGL, Qt, work with videos, etc, here is where we are need to set. Just execute the following line at the terminal to create the appropriate Makefile. Note that there is and it means the parent direc in the end of the line, it's an argument for the CMake program Tory (because we are inside the build directory, and we want to refer to the OpenCV directory, which was its parent).

-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 BU Ild_examples=on-d with_qt=on-d With_opengl=on.

Check that the above command produces no error and this in particular it reports FFMPEG as YES. If This isn't the case, you won't be a able to read or write videos. Also, check that Python, TBB, OpenGL, V4L, OpenGL and Qt is 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, compile and install OpenCV 2.4.9:

Makesudo make Install

Now there are to configure OpenCV. First, open the opencv.conf file with the following code:

sudo gedit/etc/ld.so.conf.d/opencv.conf

Add the following line at the end of the file (it could be a empty file, that's OK) and then save it:

/usr/local/lib

Run The following code to configure the library:

sudo ldconfig

Now we have the to open another file:

sudo gedit/etc/bash.bashrc

Add these lines at the end of the file and save it:

Pkg_config_path= $PKG _config_path:/usr/local/lib/pkgconfigexport pkg_config_path

Finally, Close the console and open a new one, restart the computer or logout and then login again.

Now let's build some samples included in OpenCV:

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

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

Installing OpenCV 2.4.1 in Ubuntu 12.04 LTS

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.