Configure and test OpenCV 2.4.9 in Ubuntu 14.04

Source: Internet
Author: User

Configure and test OpenCV 2.4.9 in Ubuntu 14.04

The purpose of writing this article is to facilitate your study. I spent half a day searching for information on the Internet. I hope it will be helpful for you. My Ubuntu version is 14.04.

1. Preparations
Install GCC:
Sudo apt-get install build-essential

Install CMake

Sudo apt-get install cmake

Install Git (optional)

Sudo apt-get install git

Install GTK

Sudo apt-get install libgtk2.0-dev

Install pkg-config

Sudo apt-get install pkg-config

Install Python

Sudo apt-get install python3.2-dev

Install Numpy

Sudo apt-get install python-numpy

Install a media package:

Sudo apt-get install ffmpeg // I have not installed the package successfully, but it will not be affected in subsequent tests.

Install an optional media package:

Sudo apt-get install libavcodec-dev libavformat-devlibswscale-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev

2. Download and create OpenCV

I use opencv2.4.9. the compressed package name on the official website is opencv-2.4.9.zip, which can be downloaded for free on the official website.

Decompress opencv-2.4.9.zip unzip command: Decompress the package to the directory where the package is located.

Unzip opencv-2.4.9

Run the following command:

Cd opencv-2.4.9mkdir release
Cd release
Cmake-D CMAKE_BUILD_TYPE = RELEASE-DCMAKE_INSTALL_PREFIX =/usr/local ..
Make
Sudo make install

 


Add a line of code/usr/local/lib to the/etc/ld. so. conf file.

(Permission issues may occur during the modification process. If permission issues occur, enter the following command:

Sudo su

Used to obtain root permissions

Then

Gedit/etc/ld. so. conf

Edit files)


Sudo/sbin/ldconfig-v
Then follow the change volume
Sudo gedit/etc/bash. bashrc is also added in the last line
PKG_CONFIG_PATH = $ PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
Export PKG_CONFIG_PATH


Write a hello. cpp file in the home folder for testing, including # include <opencv2/core. hpp> and enter


G ++ 'pkg-config -- cflags -- libs opencv 'Hello. cpp-o hello for compilation

If no error is reported, opencv is configured successfully.

 


3. Test in qt

# Include <iostream>
# Include <opencv2/core. hpp>
# Include <opencv2/highgui. hpp>
# Include <opencv2/imgproc. hpp>
Using namespace cv;
Using namespace std;

Int main ()
{
NamedWindow ("src ");
Mat img = imread ("/home/gzhao/lena.jpg ");

If (! Img. data ){
Cout <"file not fount" <endl;
Return 1;
}
Else {
Imshow ("src", img );
WaitKey ();
Return 0;
}
}
Add the following configuration in the XXX. pro file:


INCLUDEPATH + =/usr/local/include \
/Usr/local/include/opencv \
/Usr/local/include/opencv2

LIBS + =/usr/local/lib/libopencv_highgui.so \
/Usr/local/lib/libopencv_core.so \
/Usr/local/lib/libopencv_imgproc.so

You need to put the home address under the home path in advance.

Running result diagram:

OpenCV official tutorial Chinese version (For Python) PDF

Install the required OpenCV2.4.1 package in Ubuntu Linux

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

Install OpenCV 2.4.9 in Ubuntu 14.04 and 13.10

OpenCV details: click here
OpenCV: click here

This article permanently updates the link address:

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.