OpenCV编译安装配置总结
Last updated on May 7, 2023 pm
[TOC]
Overview
check version from source
1
modules/core/include/opencv2/core/version.hpp
check informations after installation
1
2
3
4
5
6
7
8# 查看opencv版本
pkg-config --modversion opencv
# 查看opencv包含目录
pkg-config --cflags opencv
# 查看opencv库目录
pkg-config --libs opencv
Build & Installation
Dependencies
1 |
|
build with CMake
1 |
|
Uninstall
1 |
|
Errors
/usr/local/include/c++/6.2.0/cstdlib:75:25: fatal error: stdlib.h: No such file or directory
1
-D ENABLE_PRECOMPILED_HEADERS=OFF
nvcc fatal : Unsupported gpu architecture 'compute_11' CMake Error at cuda_compile_generated_matrix_operations.cu.o.cmake:206
1
2
3-D CUDA_GENERATION=Kepler
# When using cmake to do configurations,
# set the option CUDA_GENERATION to specific your GPU architectureopencv/modules/videoio/src/ffmpeg_codecs.hpp:111:7: error: ‘CODEC_ID_H263P’ was not declared in this scope
1
-D WITH_FFMPEG=OFF
Usage
using g++
1 |
|
using CMake
1 |
|
using Makefile
将opencv-3.1.0.pc和opencv-2.4.12.pc拷贝到/usr/lib/pkgconfig目录(可设置PKG_CONFIG_PATH)下, 使用opencv-3.1.0时,Makefile中为:
1 |
|
使用opencv-2.4.12时,Makefile中为:
1 |
|
Cross-Compilation
for ARM
for Android
在
platforms/android
目录执行以下代码1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43#!/usr/bin/env bash
# cd `dirname $0`/.. # platforms/
mkdir -p build_android
cd build_android
cmake \
-DCMAKE_MAKE_PROGRAM="/usr/bin/make" \
-DCMAKE_BUILD_WITH_INSTALL_RPATH=ON \
-DCMAKE_INSTALL_PREFIX="/opt/opencv_android_sdk" \
-DCMAKE_TOOLCHAIN_FILE="../android.toolchain.cmake" \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_SHARED_LIBS=ON \
-DBUILD_DOCS=OFF \
-DBUILD_EXAMPLES=OFF \
-DBUILD_PERF_TESTS=OFF \
-DBUILD_TESTS=OFF \
-DBUILD_opencv_java=OFF \
-DBUILD_opencv_face=OFF \
-DBUILD_opencv_face=OFF \
-DWITH_IPP=OFF \
-DWITH_TBB=OFF \
-DWITH_TIFF=OFF \
-DWITH_OPENEXR=OFF \
-DWITH_OPENCL=ON \
-DWITH_CUDA=OFF \
-DWITH_MATLAB=OFF \
-DOPENCV_EXTRA_MODULES_PATH="../../../../opencv_contrib-3.3.1/modules/" \
-DBUILD_ANDROID_EXAMPLES=OFF \
-DANDROID_NDK=${ANDROID_NDK} \
-DANDROID_ABI="armeabi-v7a" \
-DANDROID_ARM_NEON=TRUE \
-DANDROID_STL=gnustl_static \
-DANDROID_CPP_FEATURES="rtti exceptions" \
-DANDROID_NATIVE_API_LEVEL=23 \
-DANDROID_PLATFORM=android-23 \
-DANDROID_SDK_TARGET=23 \
-DANDROID_DISABLE_FORMAT_STRING_CHECKS=TRUE \
$@ ../../..
# -DANDROID_OPENCL_SDK="./OpenCL-SDK" \to compile for Android with
ANDROID_STL=c++_static(shared)
, use Android NDK own CMake toolchain file and clang(ref: https://github.com/opencv/opencv/issues/8742#issuecomment-385553011)1
2
3-DCMAKE_TOOLCHAIN_FILE="${ANDROID_NDK}/build/cmake/android.toolchain.cmake" \
-DANDROID_TOOLCHAIN=clang \
-DANDROID_STL=c++_static \with
platforms/android/build_sdk.py
1
2
3
4
5python build_sdk.py \
--ndk_path $ANDROID_NDK \
--sdk_path $ANDROID_SDK \
--extra_modules_path ../../../opencv_contrib-3.3.1/modules \
build_cg ../..
Python
with conda
1 |
|
with pip
1 |
|