Ubuntu18.04 install OpenCV 4.1.1

1. Install dependencies

sudo apt-get install build-essential
sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev # 处理图像所需的包
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev liblapacke-dev
sudo apt-get install libxvidcore-dev libx264-dev # 处理视频所需的包
sudo apt-get install libatlas-base-dev gfortran # 优化opencv功能
sudo apt-get install ffmpeg

2. Download and extract the installation package opencv

Sources from the official website to download the opencv, and unpack: https://opencv.org/releases/

3. Install OpenCV

Open a terminal, cd to extract the position opencv

sudo mv opencv-4.1.1 /usr/local

cd /usr/local/opencv-4.1.1

sudo mkdir build

cd build

sudo cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D CMAKE_PREFIX_PATH=/opt/Qt5.13.0/5.13.0/gcc_64/lib/cmake/Qt5 \
-D WITH_TBB=ON \
-D WITH_V4L=ON \
-D WITH_QT=ON \
-D WITH_GTK=ON \
-D WITH_OPENGL=ON \
-D WITH_VTK=ON \
-D OPENCV_GENERATE_PKGCONFIG=YES ..

sudo make -j4

sudo make install

/opt/Qt5.13.0/5.13.0/gcc_64/lib/cmake/Qt5It is the path where I Qt5Config.cmake Qt, you need into your own, if you do not opencv support Qt user interface, can -D WITH_QT=ON \and -D CMAKE_PREFIX_PATH=/opt/Qt5.13.0/5.13.0/gcc_64/lib/cmake/Qt5 \two rows deleted.
In addition, you do not specify the path "Qt5Config.cmake", compiled in cmake when you may report the following error:

CMake Error at cmake/OpenCVFindLibsGUI.cmake:18 (find_package):
Could not find a package configuration file provided by "Qt5" with any of
the following names:

 Qt5Config.cmake
 qt5-config.cmake

Add the installation prefix of "Qt5" to CMAKE_PREFIX_PATH or set "Qt5_DIR"
to a directory containing one of the above files. If "Qt5" provides a
separate development package or SDK, be sure it has been installed.

4. Environment Configuration OpenCV

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

In the file add

/usr/local/lib

Valid configuration:

sudo ldconfig

Guess you like

Origin www.cnblogs.com/raina/p/11365854.html