1. 程式人生 > >OpenCV編譯安裝配置總結

OpenCV編譯安裝配置總結

Linux

Compilation and Installation

Dependencies

sudo apt-get install build-essential  
sudo apt-get install  libgtk2.0
-dev libavcodec-dev libavformat-dev libtiff4-dev libswscale-dev libjasper-dev sudo apt-get install cmake pkg-config

CMake

#!/bin/sh
cmake \
    -D CMAKE_BUILD_TYPE=Release \
    -D CMAKE_INSTALL_PREFIX=/usr/local/opencv_249 \ 
    -D WITH_VTK=OFF \
    -D WITH_MATLAB=OFF \
    -D WITH_TBB=ON \
    -D
WITH_IPP=OFF \
-D WITH_FFMPEG=OFF \ -D WITH_V4L=ON \ -D WITH_CUDA=OFF \ -D CUDA_GENERATION=Kepler \ -D ENABLE_PRECOMPILED_HEADERS=OFF \ # -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \ ..

Make

make -j2

Make Install

sudo make install -j2

Errors

  • /usr/local/include/c++/6.2.0/cstdlib:75:25: fatal error: stdlib.h: No such file or directory

    -D ENABLE_PRECOMPILED_HEADERS=OFF

  • nvcc fatal : Unsupported gpu architecture ‘compute_11’
    CMake Error at cuda_compile_generated_matrix_operations.cu.o.cmake:206

    -D CUDA_GENERATION=Kepler
    (When using cmake to do configurations, set the option CUDA_GENERATION to specific your GPU architecture.)

  • opencv/modules/videoio/src/ffmpeg_codecs.hpp:111:7: error: ‘CODEC_ID_H263P’ was not declared in this scope

    -D WITH_FFMPEG=OFF

Other Tutorials

Check Informations

  • 檢視opencv版本
pkg-config --modversion opencv
  • 檢視opencv包含目錄
pkg-config --cflags opencv
  • 檢視opencv庫目錄
pkg-config --libs opencv

Using

Compilation

g++ `pkg-config opencv --cflags` test.cpp -o test `pkg-config opencv --libs` 

Multiple OpenCV

Installation

Ubuntu 15.04 Opencv 安裝(多版本並存)

Using

Using CMake

在opencv編譯好後,所在目錄中一般會有一個叫OpenCVConfig.cmake的檔案,這個檔案指定了CMake要去哪裡找OpenCV,設定OpenCV_DIR為包含OpenCVConfig.cmake的目錄(可設定CMAKE_MODULE_PATH),如在C++工程CMakeLists.txt中新增

set(OpenCV_DIR "/home/ubuntu/src/opencv-3.1.0/build")
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )

因此,使用哪個版本的Opencv,只要找到對應的OpenCVConfig.cmake檔案,並且將其路徑新增到工程的CMakeLists.txt中即可。

Using Makefile

將opencv-3.1.0.pc和opencv-2.4.12.pc拷貝到/usr/lib/pkgconfig目錄(可設定PKG_CONFIG_PATH)下,
使用opencv-3.1.0時,Makefile中為:

COMMON  += -DOPENCV
CFLAGS  += -DOPENCV
LDFLAGS += `pkg-config --libs opencv-3.1.0`
COMMON  += `pkg-config --cflags opencv-3.1.0`

使用opencv-2.4.12時,Makefile中為:

COMMON  += -DOPENCV
CFLAGS  += -DOPENCV
LDFLAGS += `pkg-config --libs opencv-2.4.12`
COMMON  += `pkg-config --cflags opencv-2.4.12`

Uninstall

sudo make uninstall
or
#install-mainfest.txt包含了安裝檔案的路徑
sudo cat install-manifest.txt | sudo xargs rm 

Windows