Install OpenCV under Ubuntu 14.04 using the Apt-get method

Source: Internet
Author: User

 Reproduced, please specify the source: Http://blog.csdn.net/tina_ttl

Directory (?) [+]

tags (space delimited): Linux learning OpenCV

    • Install OpenCV under Ubuntu 1404 using the Apt-get method
    • Objective
    • Installation method
    • Where is the OPENCV installed?
      • 1 OpenCV of installation source files
      • 2 OpenCV The installation location of the associated header file
      • 3 Installation location of related dynamic link libraries for OPENCV
    • 4 Linux under OpenCV and Windows OpenCV files
    • Test code
      • 1 source code
    • 2 Make
    • 3 Test procedure

1. Preface

Compared to the source code mode installation OPENCV, the installation process via apt is simpler and consumes less time. Installation via apt does not automatically generate OPENCV.PC files, so you cannot use the Pkg-config tool directly when writing makefile files, but you need to specify Opencv_core, Opencv_imgproc and other dynamic link libraries individually!

2. Installation method
    • Update Ubtuntu system software source
sudo apt-get update
    • Installing OPENCV

sudo apt-get install libcv-dev
      • The installation process takes a few minutes and the installation is completed with the following results
3. Where is the OPENCV installed? 3.1 OpenCV installation source files
    • apt-get install **This command will download the files in the/var/cache/apt/archives directory and install them. As you can see, OpenCV related. Deb files are in this directory, as shown in the original/var/cache/apt/archives directory only folder partial and file lock, but because at this time download the OPENCV related installation files, Discover a number of multiple Deb installation files under this folder!

    • In fact, after performing the above installation process, the files under these archives paths can be deleted directly! installation files are no longer required because the associated installation has ended

      • Installing this apt-get install will make the /var/cache/apt/archives directory occupy more space.
      • Fortunately, APT provides the appropriate management tools apt-get clean to remove /var/cache/apt/archives/ /var/cache/apt/archives/partial/ all packages (except those that are locked) in the file directory and file directory.
      • Examples of implementation:
        Execute the following command

        It can be found that all the files about OpenCV that have just been downloaded have been deleted.
3.2 OpenCV The installation location of the associated header file

OpenCV related header files are installed in the/usr/lib directory, which is the Linux default header file lookup path.

Installation location of related dynamic link libraries for 3.3 OpenCV
    • The dynamic link library file under Linux is the. so file

    • OPENCV related dynamic Link libraries are installed in the /usr/lib directory. These dynamic link libraries include:
      "Opencv_calib3d"--camera calibration and three-dimensional reconstruction
      "Opencv_core"--core modules, drawings and other accessibility functions
      "Opencv_features2d"--two-dimensional feature detection
      "Opencv_flann"--quick Nearest nearest search
      "Opencv_highgui"--gui user interface
      "Opencv_imgproc"--image processing
      "Opencv_legacy"--Discarded parts
      "OPENCV_ML"--Machine learning module
      "Opencv_objdetect"--target detection module
      "Opencv_ocl"--a computer Vision component module using OPENCL acceleration
      "Opencv_video"--Video analysis component

    • is a /usr/lib file in the folder related to OpenCV, for example, the first and second files are the static state link library file (LIBOPENCV_ML.A) and the dynamic link library file (libopencv_ml.so) corresponding to the machine learning module respectively.

3.4 Linux under OpenCV and Windows OpenCV files
    • The OpenCV extracted file downloaded under Windows contains 2 folders: Source+build

      • The source code for SOURCE:OPENCV (OpenCV is open source), the various libraries under the build folder are based on these sources using cmake (in fact, In addition to the source folder can be compiled in the following build of the dynamic link library and static link library, in the actual call OpenCV related library, do not need! )
      • Build: Stored opencv** Pre-compiled various libraries (**dll (dynamic link library) and Lib library (static linklibrary)), for users who use OPENCV, only use this folder is enough, You do not need to recompile these libraries by using the source code of OPENCV
    • Linux downloads are. Deb can also get dynamic link library and static link library after extracting

      In Ubuntu, a .so file is a dynamic-link library file that corresponds to a file under Windows dll
      In Ubuntu, the file .a corresponds to a file under Windows lib ; in fact, the file is a normal function to be compiled after compiling (in the GAO Slam tutorial 2nd Chapter has a simple example of how to compile a static link library)

In fact, whenever we need to use OPENCV's related libraries under any operating system, we use only its dynamic-link libraries and static-link libraries.

4. Test Code 4.1 Source
    • Create a C + + file called Test.cpp, which reads as follows
#include <opencv2/core/core.hpp>#include <opencv2/imgproc/imgproc.hpp>#include <opencv2/highgui/highgui.hpp>#include <iostream>Usingnamespace CV;UsingNamespaceStdint main (int argc, char **argv) {Mat image, Image_gray; image = Imread (argv[1], cv_load_image_color); 
                 
                  if (argc! = 
                  2 | |!image.data) { cout << "No image data\n"; return-1;} cvtcolor (Image, Image_gray, Cv_rgb2gray); Namedwindow ("image", cv_window_autosize); Namedwindow ("image Gray", cv_window_autosize); Imshow ("image", image); Imshow ("Image Gray", Image_gray ); Waitkey (0); return 0;}            
                    

    • Create a file called Makefile, and enter the following:
CC = g++# executable FileTARGET = Test# c FileSRCs = Test.cpp# destination FileOBJS =$(SRCs:. CPP=.O)# library fileDlibs =-lopencv_core-lopencv_imgproc-lopencv_highgui# Link to executable file$ (TARGET): $(objs) $ (CC) -o [email protected] $^ $ (dlibs) clean:rm- RF $ (target) $ (objs)# compilation rule [email protected] represents the first dependent file% on behalf of the target file $<.  O:%.cpp $ (CC)-o [email protected]-C $<        

1

xxxxxx
Note 1:
12 rows, 14 rows, and 17 lines preceded by tab, not a space, “makefile:12: *** 遗漏分隔符 。 停止。” this error will occur

NOTE 2:
Because the core part of OpenCV (Opencv_core), the Image Processing Section (OPENCV_IMGPROC), and the GUI part (Opencv_highgui) are used in the example, add Opencv_core, opencv_ Imgproc, Opencv_highgui dynamic link library.
Which is DLIBS = -lopencv_core -lopencv_imgproc -lopencv_highgui implemented by the statement

4.2 Make
cd 文档  # 进入程序所在目录make 
    • 1
    • 2
    • 1
    • 2

Generated two files: Test file and TEST.O file

4.3 Test procedure
./test lena.bmp
    • 1
    • 1

Run results

The function of the above program test is to convert the input image into a grayscale image, you can see that the program implemented the function, it proves that the OPENCV installation is successful

Of course, the makefile file here is very important, the specific use of the method has not been understood, to learn

In addition, what is the difference between cmake and make? Found most of the use of cmake tools, need to write CMakeLists.txt files, specifically to learn

Reference documents
[1] Raspberry Pi Learning note--apt Way installation OpenCV
[2] apt-get downloaded files in which directory

Install OpenCV under Ubuntu 14.04 using the Apt-get method

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.