Ubuntu 12.04 uses CMake-2.8.10.4 to compile OpenCV-2.4.4

Source: Internet
Author: User
Tags cairo

1. Download and install CMake for Linux

: Http://www.cmake.org/cmake/resources/software.html

The downloaded file cmake-2.8.10.2 is cmake-2.8.10.2.tar.gz.

Create the installation folder, path:/home/(your login username)/cmake, command: sudo mkdir ~ /Cmake

Decompress the cmake package, enter the created folder, and enter sudo tar zxvf./cmake-2.8.10.2.tar.gz

Compile and install, go to the folder/home/(your login username)/cmake/cmake-2.8.10.2

Command: sudo./bootstrap; sudo make install

Open the file in the user's home directory, use vim or gedit to open/etc/environment, run the command sudo gedit/etc/environment, and add the environment variable -- add a line of PATH = $ PATH in enviroment: /home/(your login username)/cmake/cmake-2.8.10.2/bin:

Recommended reading:

Install OpenCV2.4.2 on Ubuntu 12.04

OpenCV in CentOS cannot read Video Files

Summary of installing OpenCV 2.4.5 in Ubuntu 12.04

Install OpenCv2.1 in Ubuntu 10.04

Face Recognition System Based on QT and OpenCV

2. Download Opencv for linux

First download the opencv source file package: http://www.opencv.org.cn/download/OpenCV-2.4.4a.tar.bz2

Create the opencv installation directory/home/(your logon username)/OpenCV/and run the following command: sudo mkdir ~ /OpenCV

Decompress the file and put it in/home/(your login user name)/OpenCV/

3. install necessary libraries before compiling and installing opencv2.4.4.

The installation method is as follows: sudo apt-get install build-essential libtiff4-dev libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg62-dev cmake libswscale-dev libjasper-dev pkg-config, some may have been installed, but it is best to confirm that all of the above have been installed. Moreover, apt-get of ubuntu is very convenient to use.

The above packages are necessary, but some dependency errors may occur during the installation process:

Such as: Dependency: *****> (2.3.1), but ***** cannot be installed.

Solution: sudo aptitude install (the file to be installed)

Then select Y or N. Selecting Y means solving the problem according to the provided method. Selecting N means that you do not agree with the solution provided. The system will provide a new solution! This is the most appropriate solution that should be selected on your own.

There are still some problems, especially the prompt that the GTK installation package will depend on pango, and pango will depend on cairo. During pango compilation, a problem may occur and a prompt will be prompted for Disabling cairo support. This is very important. Here we need to modify the pango configure file. You can use gedit to open the configure file and then add the command: have_cairo = true before Disabling cairo support; in this way, you can.

Here, we will discuss other issues in detail.

4. You do not need to modify the source code of OpenCV2.4.4.

5. Compile and install OpenCV2.4.4

Run the cmake command in the OpenCV2.4.4 Folder: sudo cmake-D CMAKE_BUILD_TYPE = RELEASE-D CMAKE_INSTALL_PREFIX =/usr/local-D BUILD_PYTHON_SUPPORT = ON ~ /OpenCV/opencv-2.4.4

If this fails, the majority of the reason is that the library in step 3rd is not installed. At this time, we should analyze the specific situation. Read the compilation failure prompts and solve them one by one!

Makefile is generated. The default installation directory is/usr/local.

Then enter sudo make

After the installation is complete, run the following command: sudo make install.

Next, add the environment variable of the opencv Library to the system (that is, the inventory path, note that it is not the decompression path)

Use vim to open/etc/ld. so. conf. Be sure to use sudo to open and obtain the permission. Otherwise, the permission cannot be modified, for example, sudo vim/etc/ld. so. conf: Add/usr/loacal/lib to the file, and/user/loacal is the installation path specified in makefile.

Run sudo ldconfig again,

Modify the environment file, sudo gedit/etc/environment

Add the following content to the end of the file:

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

Export PKG_CONFIG_PATH

Open a new console and restart or log out.

Compilation and installation are complete! Pai_^

6. First test OpenCV

Here we try to compile and run the example in sample/c provided by opencv.

According to the instructions in the sample, create a example-release folder to store the compilation result. Run the sudo mkdir ~ command ~ /Home/(your login username)/Opencv/OpenCV-2.1.0/samples/c/sample-release

Then go to the created folder cd ~ /Home/(your login username)/Opencv/OpenCV-2.1.0/samples/c/sample-release

Use cmake to generate the makefile file. The command is as follows: cmake ~ Cd ~ /Home/(your logon username)/Opencv/OpenCV-2.4.4/samples/c/example_cmake

Then compile in sample-release with the command: make

OK, the executable file is generated successfully!

Finally, let's take a look at the effect. Enter:./opencv_example

This is the circle & rect pattern that should be output on the screen.

7. Now, we are done! And, enjoy it!

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.