How to install OpenCV on Linux

Steps on how to install OpenCV on a Linux system:

Update your system: Type e in Terminal sudo apt-get update 和 sudo apt-get upgradto update your system.

Dependencies required to install OpenCV: Type in the terminal sudo apt-get install build-essential cmake pkg-configto install the dependencies required by OpenCV.

Install the Image I/O library: Type in a terminal sudo apt-get install libjpeg-dev libtiff5-dev libjasper-dev libpng12-devto install the Image I/O library.

Install the Video I/O library: Type in a terminal sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev libxvidcore-dev libx264-devto install the Video I/O library.

Install the GUI library: Type sudo apt-get install libgtk-3-dev in a terminal to install the GUI library.

Download OpenCV source code: You can download OpenCV source code from OpenCV official website, or enter in terminal wget -O opencv.zip https://github.com/opencv/opencv/archive/4.5.1.zipto download directly.

Unzip the OpenCV source code: Type unzip opencv.zip in the terminal to unzip the OpenCV source code.

Create and enter the build directory: Enter in the terminal cd opencv-4.5.1/ 和 mkdir buildto create and enter the build directory.

Run CMake: type in terminalcmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..

Compile and install OpenCV: Enter in the terminal make -j4and wait for the compilation to complete, then enter sudo make installto install OpenCV.

Update the dynamic link library: Enter in the terminal sudo ldconfigto update the dynamic link library.

Verify the installation: Enter python3 in the terminal, and then enter import cv2 in the Python interactive environment. If there is no error, the installation is successful.

The above are the steps on how to install OpenCV on the Linux system. Hope you can install successfully!

Guess you like

Origin blog.csdn.net/weixin_47665864/article/details/128945476