Ubuntu11.04 detailed description of OpenCV2.2 compilation and Installation

Source: Internet
Author: User
1. Download and install CMakeforLinux: Installation

1. Download and install CMake for Linux
: Http://www.cmake.org/cmake/resources/software.html
The downloaded file cmake-2.8.4 is cmake-2.8.4.tar.gz.

Create the installation folder, path:/home/(your login username)/cmake, command: sudo mkdir ~ /Home/(your login username)/cmake
Decompress the cmake package, enter the created folder, and enter tar zxvf./cmake-2.8.4.tar.gz
Compile and install, go to the folder/home/(your login username)/cmake/cmake-2.8.4, command: sudo./bootstrap; make install

Open in the user's home directory, use vim or gedit to open/home/(your login username )/. bashrc, add a line PATH = $ PATH:/home/(your login username)/program/cmake/cmake-2.8.4/bin:
2. Download Opencv for linux
First download the opencv source file package: http://www.opencv.org.cn/download/OpenCV-2.1.0.tar.bz2
Create the opencv installation directory/home/(your logon username)/Opencv/and run the following command: sudo mkdir ~ /Home/(your login username)/Opencv
Decompress the file, command tar jxvf./OpenCV-2.1.0.tar.bz2
3. install some necessary libraries before compiling and installing opencv2.2.
The installation method is as follows: sudo apt-get install build-essential 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.
4. Modify OpenCV2.2 source code
Before compilation, you need to make a patch Ticket #862: OpenCV-2.2-nov4l1.patch, otherwise the compilation will report an error and stop at around 80%, in fact, just changed the several lines of code in the two files, the modification is as follows:
OpenCV-2.2.0/modules/highgui/src/cap_v4l.cpp 217 row
# Include


| Change
# Ifdef HAVE_CAMV4L
# Include
# Endif
OpenCV-2.2.0/modules/highgui/src/cap. cpp 174 row
# If defined (HAVE_CAMV4L) | defined (HAVE_CAMV4L2)
| Change
# If defined (HAVE_CAMV4L)
Complete
5. Compile and install OpenCV2.2
Create the build folder in the decompressed directory and run the cmake command: cmake-D CMAKE_BUILD_TYPE = RELEASE-D CMAKE_INSTALL_PREFIX =/usr/local-D BUILD_PYTHON_SUPPORT = ON ..
Note that input "..." indicates the upper-level directory
Makefile is generated. The default installation directory is/usr/local.
Then input make in the directory where the build is just created under the extract directory of OpenCV.
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 bash. bashrc file, sudo gedit/etc/bash. bashrc
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.1.0/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
O (zookeeper) o... haha, we need something!

Related Article

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.