11 feb 2022

opencv build



method

https://linuxize.com/post/how-to-install-opencv-on-ubuntu-20-04/




**EDIT to update

git pull in both opencv and opencv_contrib

cd opencv/build

cmake .

make etc...


So, in case it does a disappearing act:

--- --- ---

  1. Install the build tools and dependencies:

    sudo apt install build-essential cmake git pkg-config libgtk-3-dev \    libavcodec-dev libavformat-dev libswscale-dev libv4l-dev \    libxvidcore-dev libx264-dev libjpeg-dev libpng-dev libtiff-dev \    gfortran openexr libatlas-base-dev python3-dev python3-numpy \    libtbb2 libtbb-dev libdc1394-22-dev libopenexr-dev \    libgstreamer-plugins-base1.0-dev libgstreamer1.0-dev
  2. Clone the OpenCV’s and OpenCV contrib repositories:

    mkdir ~/opencv_build && cd ~/opencv_buildgit clone https://github.com/opencv/opencv.gitgit clone https://github.com/opencv/opencv_contrib.git

    At the time of writing, the default version in the github repositories is version 4.3.0. If you want to install an older version of OpenCV, cd to both opencv and opencv_contrib directories and run git checkout <opencv-version>

  3. Once the download is complete, create a temporary build directory, and navigate to it:

    cd ~/opencv_build/opencvmkdir -p build && cd build

    Set up the OpenCV build with CMake:

    cmake -D CMAKE_BUILD_TYPE=RELEASE \    -D CMAKE_INSTALL_PREFIX=/usr/local \    -D INSTALL_C_EXAMPLES=ON \    -D INSTALL_PYTHON_EXAMPLES=ON \    -D OPENCV_GENERATE_PKGCONFIG=ON \    -D OPENCV_EXTRA_MODULES_PATH=~/opencv_build/opencv_contrib/modules \    -D BUILD_EXAMPLES=ON ..

    The output will look something like below:

    -- Configuring done
    -- Generating done
    -- Build files have been written to: /home/vagrant/opencv_build/opencv/build
  4. Start the compilation process:

    make -j8

    Modify the -j flag according to your processor. If you do not know the number of cores in your processor, you can find it by typing nproc.

    The compilation may take several minutes or more, depending on your system configuration.

  5. Install OpenCV with:

    sudo make install
  6. To verify the installation, type the following commands and you should see the OpenCV version.

    C++ bindings:

    pkg-config --modversion opencv4
    4.3.0

    Python bindings:

    python3 -c "import cv2; print(cv2.__version__)"
    4.3.0-dev

No hay comentarios:

Publicar un comentario