ubuntu mounted Opencv 4.1.1

1, enter Opencv official website, download Opencv 4.1.1.zip, and placed under linux working directory;

2, unzip command to extract;

3. Installation depends tools:

  sudo apt-get install cmake;

  sudo apt-get install build-essential;

  sudo apt-get install libgtk2.0-dev (version 2.0 or more);

  sudo apt-get install pkg-config;

  sudo apt-get install python-dev python-numpy;

  sudo apt-get install libavformat-dev libavcodec-dev libswscale-dev libtbb2 libtbb-dev libjpeg-dev libpng12-dev libtiff5-dev libjasper-dev libdc1394-22-dev;

4、cd opencv-4.1.1;

       mkdir release;

  cmake -DCMAKE_BUILD_TYPE=Release -DOPENCV_GENERATE_PKGCONFIG=ON -DCMAKE_INSTALL_PREFIX=/usr/local ..;

  opencv4 default does not generate .pc files, plus OPENCV_GENERATE_PKGCONFIG = ON will be generated, resulting opencv4.pc stored in the / usr / local / lib / pkgconfig (note generated is not opencv.pc, version reason behind compile time parameters It should be opencv4 instead opencv);

5, make -j8; (make when possible because of insufficient memory error, c ++: internal compiler error: Killed (program cc1plus, at run time can be assigned multi-point memory to Ubuntu, I use a virtual machine directly allocated 8G, memory is not enough, then you can find online swap solutions)

  sudo make install;

6, configuration C ++: sudo nano /etc/ld.so.conf.d/opencv4.conf, the last line (it does not matter if the file is empty) Add / usr / local / lib;

7, configuration repository: sudo ldconfig;

8, adding environment variables: sudo gedit / etc / profile and finally add export PATH = "/ usr / local / lib / pkgconfig: $ PATH", after what source;

9, g ++ test.cpp -o test `pkg-config --cflags --libs opencv4` Description:` pkg-config --cflags --libs opencv4` tell the program to find the appropriate headers and libraries from opencv4.pc inside.

10, an error

/usr/local/include/opencv4/opencv2/core/cvdef.h:690:4: error: #error "The requires Enabled OpenCV 4.x + 11 C ++ Support"
# error "OpenCV The requires Enabled C ++ 4.x + 11 support "should be the reason for the current compilation environment in C ++ 11 version of the following;

11, gcc 5.4.0 version I use, seemingly by default does not support C ++ 11, need to add -std = c ++ 11 at compile time,

g ++ -std = c ++ 11 test.cpp -o test `pkg-config --cflags --libs opencv4` thus adopted.

Guess you like

Origin www.cnblogs.com/lonelypinky/p/11579911.html