linux安装c++ opencv

wget -O opencv.zip https://github.com/opencv/opencv/archive/4.x.zip
wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.x.zip
unzip opencv.zip
unzip opencv_contrib.zip
# Create build directory and switch into it
mkdir -p build && cd build
# Configure
cmake -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib-4.x/modules ../opencv-4.x -DCMAKE_INSTALL_PREFIX=/usr/local
##-DCMAKE_INSTALL_PREFIX指定安装目录
# Build
cmake --build . -j8
make install -j8

CMakeLists.txt编写示例

cmake_minimum_required(VERSION 3.20)
set(CMAKE_CXX_STANDARD 20)
PROJECT(opencv_test)



find_package(OpenCV REQUIRED PATHS /newhome/wangjd/local NO_DEFAULT_PATH)//会以OpenCV为前缀 去目录下找 opencvconfig.cmake文件
//PATHS指定路径
include_directories(${OpenCV_INCLUDE_DIRS})
add_executable(opencv_test main.cpp)
target_link_libraries(opencv_test ${OpenCV_LIBS})

你可能感兴趣的:(c++,opencv,opencv,linux,c++)