Instalar OpenCV
Microsoft Windows
Microsoft Windows 11
WSL 2
Ubuntu 22.04.04 LTS
Instalar los paquetes:
sudo apt update sudo apt install build-essential sudo apt install cmake sudo apt install git sudo apt install pkg-config libgtk-3-dev sudo apt install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev libxvidcore-dev libx264-dev sudo apt install libjpeg-dev libpng-dev libtiff-dev gfortran openexr libatlas-base-dev sudo apt install python3-dev python3-numpy libtbb2 libtbb-dev libdc1394-25 libdc1394-dev
OpenCV:
cd ~ mkdir opencv_with_contrib cd opencv_with_contrib git clone https://github.com/opencv/opencv.git git clone https://github.com/opencv/opencv_contrib.git cd opencv git checkout 4.x cd ../opencv_contrib git checkout 4.x cd ..
Compilar OpenCV:
mkdir build cd build cmake -DCMAKE_BUILD_TYPE=RELEASE -D OPENCV_GENERATE_PKGCONFIG=ON -DOPENCV_ENABLE_NONFREE=ON -DENABLE_PRECOMPILED_HEADERS=OFF -DOPENCV_EXTRA_MODULES_PATH=~/opencv_with_contrib/opencv_contrib/modules -DBUILD_opencv_legacy=OFF -DCMAKE_INSTALL_PREFIX=/usr/local ../opencv nproc #increasing the number will make building faster. Maximum value can be found by running nproc. make -j4 sudo make install
Ahora creamos un código en Python:
Nombre del archivo main.py
import cv2 cv2.__version__
Lo ejecutamos:
python3 main.py
OBS:
- Si sale error, es porque no se instalo correctamente OpenCV en Ubuntu (WSL).