# Install the newest versions of all packages currently installed sudo apt-get -y upgrade # Handles changing dependencies with new versions of packages sudo apt-get -y dist-upgrade # Remove packages that are now no longer needed sudo apt-get -y autoremove
# Build tools: sudo apt-get install -y build-essential cmake # GUI (if you want to use GTK instead of Qt, replace 'qt5-default' with 'libgtkglext1-dev' and remove '-DWITH_QT=ON' option in CMake): sudo apt-get install -y qt5-default libvtk6-dev # Media I/O: sudo apt-get install -y zlib1g-dev libjpeg-dev libwebp-dev libpng-dev libtiff5-dev libjasper-dev libopenexr-dev libgdal-dev # Video I/O: sudo apt-get install -y libdc1394-22-dev libavcodec-dev libavformat-dev libswscale-dev libtheora-dev libvorbis-dev libxvidcore-dev libx264-dev yasm libopencore-amrnb-dev libopencore-amrwb-dev libv4l-dev libxine2-dev # Parallelism and linear algebra libraries: sudo apt-get install -y libtbb-dev libeigen3-dev # Python: sudo apt-get install -y python-dev python-tk python-numpy python3-dev python3-tk python3-numpy # Java: sudo apt-get install -y ant default-jdk # Documentation: sudo apt-get install -y doxygen
mkdir build & cd build sudo cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D WITH_EIGEN=ON .. sudo make # compile sudo make install # install sudo ldconfig # load config
在Cmake構建的項目中,須要在CmakeLists.txt中添加find_package 和target_link_libraries,幫助cmake構建時候查找包與庫
html
find_package(OpenCV REQUIRED) target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBRARIES})
添加好opencv庫的cmake工程文件相似以下:python
cmake_minimum_required(VERSION 2.8.12) project(SongCamera) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_AUTOMOC ON) find_package(Qt5Core REQUIRED) find_package(OpenCV REQUIRED) FILE(GLOB SC_FILES "*.cpp" "*.h") add_executable(${PROJECT_NAME} ${SC_FILES}) target_link_libraries(${PROJECT_NAME} Qt5::Core Qt5::Gui Qt5::Qml Qt5::Quick) # 指定lib庫的位置 target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBRARIES})
Qmake構建Qt程序更方便, 在構建OpenCV的程序時候須要添加Include的文件夾和庫,在這裏注意include的路徑要包含opencv4那一級.添加庫後的.pro文件以下:web
#------------------------------------------------- # # Project created by QtCreator 2020-10-22T23:07:21 # #------------------------------------------------- QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = EagleEye TEMPLATE = app # The following define makes your compiler emit warnings if you use # any feature of Qt which has been marked as deprecated (the exact warnings # depend on your compiler). Please consult the documentation of the # deprecated API in order to know how to port your code away from it. DEFINES += QT_DEPRECATED_WARNINGS # You can also make your code fail to compile if you use deprecated APIs. # In order to do so, uncomment the following line. # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ main.cpp \ mainwindow.cpp \ cvwidget.cpp HEADERS += \ mainwindow.h \ cvwidget.h FORMS += \ mainwindow.ui ##>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> INCLUDEPATH += /usr/local/include\ /usr/local/include/opencv4/opencv2\ /usr/local/include/opencv4 LIBS+=/usr/local/lib/libopencv_highgui.so\ /usr/local/lib/libopencv_core.so\ /usr/local/lib/libopencv_imgproc.so\ /usr/local/lib/libopencv_imgcodecs.so\ /usr/local/lib/libopencv_videoio.so ##<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Ubuntu18源碼編譯OpenCV4.3ubuntu