Steps on how to install OpenCV on a Linux system:
Update your system: Type e in Terminal sudo apt-get update 和 sudo apt-get upgrad
to update your system.
Dependencies required to install OpenCV: Type in the terminal sudo apt-get install build-essential cmake pkg-config
to 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-dev
to 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-dev
to 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.zip
to 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 build
to 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 -j4
and wait for the compilation to complete, then enter sudo make install
to install OpenCV.
Update the dynamic link library: Enter in the terminal sudo ldconfig
to 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!