"Learn OpenCV from zero" UBUNTU+OPENCV+QT installation configuration

Source: Internet
Author: User

One, Ubuntu installation

Ubuntu is a Linux distribution, I think people who know about Linux should know that we directly to the official online download is good, is free to use.

Website download link

I'm using the newest ubuntu14.04 here.

Because I am using the Mac system, directly with the VMware fusion7 virtual machine will download a good mirror CD-ROM installation can be, and the real system installation, Ubuntu installation process is very user-friendly, all the way to set the past.


Second, OPENCV installation

First find OpenCV's official website to download the latest OpenCV package to Ubuntu, Portal: OpenCV download



Download complete directly right key decompression, of course, you can also use Shell:unzip opencv-2.4.10.zip

After decompression do not worry, you will see the extract directory has a pile of files, this is our OpenCV library, but now can not be used, you have to use CMake to compile the line.

CMake is a cross-platform compiler, in Ubuntu we only need to enter a line of instructions: Apt-get install CMake can be installed

Of course, if you think the installed version is not suitable, you can go to cmake website download the corresponding version: CMake download

Here we choose to compile a good version cmake-3.1.0-rc1-linux-i386.tar.gz

Tar zxvf cmake-3.1.0-rc1-linux-i386.tar.gz–c/usr/local/

To set environment variables:

sudo gedit/home/panda/.bashrc

To add after an open file:

Export path= $PATH:/usr/local/cmake-3.1.0-rc1-linux-i386/bin

To view the version, test whether the installation was successful:

root@panda:/home# CMake--version
CMake version 3.1.0

CMake installed after the installation of some other bags, through apt to get the good:

sudo apt-get install build-essential cmake libgtk2.0-dev pkg-config python-dev python-numpy Libavcodec-dev Libavformat-dev Libswscale-dev

Now that we can start compiling opencv, we go to the OpenCV directory:

CD opencv-2.4.10

Create a new Release folder (it doesn't matter what you name it) for storing the compiled file:

mkdir Release

Then enter the release directory: CD release

At this time can execute CMake, usr/local is a lib file storage directory

Cmake-d cmake_build_type=release-d cmake_install_prefix=/usr/local.

Continue to enter command after end: sudo make

Next: sudo make install

This completes the compilation, you can see the compiled OPENCV function library under the Usr/local/lib


It's not over yet, and finally you have to configure the OPENCV environment variable:

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


After opening the file, add/usr/local/lib at the end, save exit after execution: sudo ldconfig

Then configure the environment variable: sudo GEDIT/ETC/BASH.BASHRC


Go to the end of this file, write
Pkg_config_path= $PKG _config_path:/usr/local/lib/pkgconfig Export Pkg_config_path

This OPENCV configuration is complete.


Third, QT installation

Find Qt's official download site first: http://qt-project.org/downloads

Because I am more familiar with the QT4, so downloaded the Qt libraries 4.8.6 for linux/x11, while downloading a very personal favorite matching ide:qt Creator for 3.2.1 linux/x11

First of all, download the good QT Libraries decompression: Tar zxvf qt-everywhere-opensource-src-4.8.6.tar.gz

Next into the Decompression directory: CD qt-everywhere-opensource-src-4.8.6/

Execute configure:./configure

A hint appears in the configuration:

Which edition of Qt do your want to use?
Type ' C ' If you are want to use the commercial Edition.
Type ' O ' If you are want to use the ' Open Source Edition.

Of course input O

and then:

This is the Open Source Edition.

You are are licensed to use this software under the terms of
The Lesser GNU general public License (LGPL) versions 2.1.
You are are also licensed to use this software under the terms of
The GNU general public License (GPL) versions 3.

Type ' 3 ' to view the GNU general public License version 3.
Type ' L ' to view the lesser GNU License version 2.1.
Type ' yes ' to accept this license offer.
Type ' No ' to decline this license offer.

Do you accept the terms of either license?

Enter Yes and then spend a period of time producing makefile, after which you enter: Make

Then you have to wait 3 hours for compilation, and when you're done, enter: sudo make install

After the installation is complete, it will be in the usr/local/trolltech/qt-4.8.6 directory


Executing the compiler qmake placed under Usr/bin to indicate that the installation was successful.


The next thing is to install the Qt Creator, qt-creator-opensource-linux-x86_64-3.2.1 the downloaded installation file to change the file properties to make it executable.

chmod u+x qt-creator-opensource-linux-x86_64-3.2.1

Then run sudo./qt-creator-opensource-linux-x86_64-3.2.1

The next step is to simply install the boot interface.

Once the installation is complete, we can start using QT to write the OPENCV program.


Four, OPENCV test case

Let's turn on Qt Creator, create a new project, and select the console program here:


When you are finished, you will see the following items:


Modify the Test.pro file first:

#-------------------------------------------------
#
Project created by Qtcreator 2014-11-03t21:27:45
#
#-------------------------------------------------

qt =       core

qt-       = GUI

TARGET = Test
CONFIG   + = Console CONFIG-=   app_bundle

TEMPLATE = App


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

SOURCES + + main.cpp
The main is to add a reference to the OPENCV function library

The main function main.cpp is modified as follows:

#include <QCoreApplication>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/ highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>

using namespace CV;

int main (int argc, char *argv[])
{
//    qcoreapplication A (argc, argv);

    Namedwindow ("src", window_autosize);
    Mat Src1 = Imread ("lena.jpg");
    while (1)
    {
        imshow ("src", src1);
        char C =  waitkey ();
        if (27==c) return
            0;
    }


return    a.exec ();
}
Then in the engineering root directory of the lena.jpg picture, press Ctrl+r can be compiled and run, the effect is as follows:


This program is very simple, that is, using imshow to display an image, press ESC to exit the program, and then continue to introduce Ubuntu under the use of Qt to write a OPENCV program of some cases.


(reprint please indicate the author and the Source: Shawn-ht http://blog.csdn.net/shawn_ht do not use for commercial purposes without permission

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.