-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_opencv.txt
54 lines (38 loc) · 2.21 KB
/
install_opencv.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
Installing OpenCV from the Source
Building the OpenCV library from source is the recommended way of installing OpenCV. It will be optimized for your particular system and you will have complete control over the build options.
To install the latest OpenCV version from the source, perform the following steps:
Install the required 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
Clone the OpenCV's and OpenCV contrib repositories:
mkdir ~/opencv_build && cd ~/opencv_build
git clone https://github.com/opencv/opencv.git
git clone https://github.com/opencv/opencv_contrib.git
At the time of writing, the default version in the github repositories is version 4.2.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>
Once the download is complete, create a temporary build directory, and switch to it:
cd ~/opencv_build/opencv
mkdir 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 ..
When the CMake build system is finalized, you will see something like below:
Start the compilation process:
make -j8
Modify the -j flag according to your processor. If you do not know the number of cores your processor, you can find it by typing nproc.
The compilation may take several minutes or more, depending on your system configuration. Once it is completed you will see something like below:
Install OpenCV with:
sudo make install
To verify whether OpenCV has been installed successfully, type the following command and you should see the OpenCV version:
pkg-config --modversion opencv4
4.2.0
python3 -c "import cv2; print(cv2.__version__)"
Copy
4.2.0-dev