Descarga, configura, instala y compila opencv en Ubuntu

1 Instalar dependencias relacionadas

Antes de instalar opencv, debe preparar el compilador y las dependencias relacionadas

sudo apt-get install gcc g++ cmake vim
sudo apt-get install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg-dev libswscale-dev libtiff5-dev
sudo apt-get install libgtk2.0-dev
sudo apt-get install pkg-config

Si sudo no está instalado, entonces

apt-get update
apt-get install sudo

2 descargas

git clone https://gitcode.net/opencv/opencv

3 configuración

cd opencv
mkdir build
cd build

sudo cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local .. -D OPENCV_GENERATE_PKGCONFIG=ON

Cabe señalar que se debe establecer " -D OPENCV_GENERATE_PKGCONFIG=ON " , de lo contrario, se informará un error al ingresar el siguiente comando,

pkg-config --cflags opencv

Package opencv was not found in the pkg-config search path.
Perhaps you should add the directory containing `opencv.pc'
to the PKG_CONFIG_PATH environment variable
No package 'opencv' found

4 compilar

sudo make -j [número de subprocesos], como

sudo make -j8

5 instalación

sudo make install

6 Configuración del entorno

  1. Modificar /etc/ld.so.conf

sudo vim /etc/ld.so.conf

Después de abrir el archivo, agregue al final

include /usr/local/lib

Ingrese el siguiente comando para actualizar la biblioteca de enlaces compartidos del sistema

sudo ldconfig
  1. Modificar /etc/bash.bashrc

sudo vim /etc/bash.bashrc

Después de abrir el archivo, agregue al final

PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH

activar perfil

source /etc/bash.bashrc

7 Ver versión

pkg-config opencv4 --modversion

Supongo que te gusta

Origin blog.csdn.net/qq_38964360/article/details/129739804
Recomendado
Clasificación