编译ubuntu18.04编译opencv 4.20

参考:Ubuntu 编译OpenCV详细教程_opencv编译ubuntu_原我归来是少年的博客-CSDN博客

1.安装依赖库sudo apt-get install build-essential cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libdc1394-22-dev libgtk-3-dev libgtkglext1-dev libgstreamer1.0-dev libavresample-dev  libgphoto2-dev libopenblas-dev libatlas-base-dev doxygen libgstreamer-ocaml-dev libgstreamer-plugins-bad1.0-dev libgstreamer-plugins-base1.0-dev libgstreamer-plugins-good1.0-dev libgstreamer1.0-dev libgstreamermm-1.0-dev libtesseract-dev liblept5 libleptonica-dev liblapacke-dev libgstreamer-opencv1.0-0 libgstreamer-plugins-bad1.0-dev libgstreamer-plugins-base1.0-dev libgstreamer-plugins-good1.0-dev libgstreamerd-3-dev libgstreamermm-1.0-dev libv4l-dev libprotobuf-dev libhdf5-dev libgflags-dev python3-numpy

2.解压opencv4.2.0-master.zip: unzip opencv4.2.0-master.zip

3.cp opencv_contrib-4.2.0.zip opencv4.2.0-master  unzip opencv_contrib-4.2.0.zip

4.进入目录:cd release  
不需要CUDA:cmake -D CMAKE_BUILD_TYPE=RELEASE \
    -D CMAKE_INSTALL_PREFIX=/usr/local/opencv342 \  
    -D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib-3.4.2/modules \  
    -D WITH_LIBV4L=ON \
     -D WITH_CUDA=OFF \
    -D WITH_TBB=ON \
    -D WITH_OPENMP=ON \
    -D WITH_OPENGL=ON ..

编译:sudo make -j8

测试: 按照参考连接,还不错的cmakelist.txt

cmake_minimum_required(VERSION 3.1) # 选择最匹配的最低的Cmake版本
project( DisplayImage ) # 创建的程序的名称(项目的名称)
find_package( OpenCV REQUIRED ) # 找到需求的库或者组件
include_directories( ${OpenCV_INCLUDE_DIRS} ) # 添加一个用于包含的文件去构建的文件夹
add_executable( DisplayImage main.cpp ) # 添加参与编译的项目完整包
target_link_libraries( DisplayImage ${OpenCV_LIBS} ) # 链接的库

你可能感兴趣的:(opencv,ubuntu,人工智能)