Get opencv source
git clone [email protected]:opencv/opencv.git
to obtain opencv_contrib Source
git clone [email protected]:opencv/opencv_contrib.git
list all tag
git tag -l
Here, for example to install 3.4.7
git checkout tags/3.4.7
opencv_contrib also use this method of detection corresponding version of the source code, note the version number strictly consistent, otherwise there will be problems
To avoid contamination file, first create a directory where the compiler generates a file for
mkdir build
cd build
In this directory run cmake
cmake -DCMAKE_BUILD_TYPE=Release -DOPENCV_GENERATE_PKGCONFIG=ON -DCMAKE_INSTALL_PREFIX=/usr/local/opencv347 -DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules/ ..
- -DOPENCV_GENERATE_PKGCONFIG = ON opencv4 default does not produce pc files, you need to open this
- Installation path -DCMAKE_INSTALL_PREFIX = / usr / local / opencv347 opencv may be omitted, the default will be installed / usr / local directory
- -DOPENCV_EXTRA_MODULES_PATH = .. / .. / opencv_contrib / modules / opencv_contrib compiled with the opencv and, if this does not need to be removed opencv_contrib
Then a waiting
After the successful implementation of the following command to start compiling, here opened eight threads
make -j8
Then execute
sudo make install
Configuration
cd /etc/ld.so.conf.d/
sudo touch opencv347.conf
# 根据安装位置
sudo sh -c 'echo "/usr/local/opencv347/lib" > opencv347.conf'
sudo ldconfig
Copy the files pc
sudo cp -f /usr/local/opencv347/lib/pkgconfig/opencv.pc /usr/lib/pkgconfig/opencv347.pc
have a test
pkg-config --modversion opencv347
test program
cpp
#include <opencv2/core.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main(int argc, char **argv) {
cout << "OpenCV version : " << CV_VERSION << endl;
cout << "Major version : " << CV_MAJOR_VERSION << endl;
cout << "Minor version : " << CV_MINOR_VERSION << endl;
cout << "Subminor version : " << CV_SUBMINOR_VERSION << endl;
return 0;
}
cmake
cmake_minimum_required(VERSION 3.14)
project(opencvhelloworld)
set(CMAKE_CXX_STANDARD 14)
find_package( OpenCV 3.4.7 REQUIRED )
add_executable(opencvhelloworld main.cpp)
target_link_libraries( opencvhelloworld ${OpenCV_LIBS} )
After running the version number can be seen opencv
cmakelist file modification find_package( OpenCV 3.4.7 REQUIRED )
may introduce other versions
cmake
cmake_minimum_required(VERSION 3.14)
project(opencvhelloworld)
set(CMAKE_CXX_STANDARD 14)
find_package( OpenCV 4 REQUIRED )
add_executable(opencvhelloworld main.cpp)
target_link_libraries( opencvhelloworld ${OpenCV_LIBS} )
This is achieved by 4.1.1 pacman mounted, can also be incorporated using this method
references
- Arch / Manjaro Linux compiler configuration under Opencv View
- How to compile opencv3 and opencv_contrib (Linux)
- Under ubuntu16.04 opencv3.2 compile and install opencv_contrib
- OpenCV_contrib Module Overview
- CMakeLists.txt add opencv Library Notes
- CMake can not find a solution opencv library
- CMakeLists.txt add opencv Library Notes
- Set Opencv path for a c++ project using Cmake
- How to Have Multiple Versions of OpenCV Side by Side
- cmake Concise Guide
- linux compiler written in C ++ opencv program
- Linux uses a custom path to run under OpenCV
- Source Package installation and pkg-config
- Pkg-config encyclopedia Wikipedia, the free
- Understanding of Linux in the pkg-config tool
- Role /etc/ld.so.conf.d/ directory files
- Install opencv (c ++) compiler undefined reference error solutions linux environment
- c - Error: 'create' not 'cv :: Tracker' members
- How to make the gcc compiler error messages in English way output
- How output OpenCV version number in Python and C ++
- KCF run opencv tracking pit configuration opencv_contrib encountered