table des matières
Modifier la méthode de fichier
Une meilleure solution - changer la version d'OpenCV
3.4.1 version d'OpenCV et d'OpenCV_contrib
Télécharger le fichier source de xfeatures2d
Contexte
Enregistrez le processus d'installation d'OpenCV3 sur Ubuntu 18.04 64 bits il y a quelque temps. Si vous avez de la chance, c'est très fastidieux, juste pour référence.
Installer les dépendances
root@sundata:/etc/apt/sources.list.d# apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev libx264-dev libx265-dev
root@sundata:/etc/apt/sources.list.d# apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libdc1394-22-dev ffmpeg libavformat-dev libavcodec-dev libswresample-dev libswscale-dev libavutil-dev libsdl1.2-dev yasm
Installez ffmpeg
root@sundata:/data/szc# git clone git://source.ffmpeg.org/ffmpeg.git ffmpeg
root@sundata:/data/szc# cd ffmpeg/
root@sundata:/data/szc/ffmpeg# ./configure --enable-shared --prefix=/usr/local/ffmpeg --enable-gpl --enable-libx264 --enable-libx265
root@sundata:/data/szc/ffmpeg# make && make install
Si une erreur est signalée lors de la compilation: V4L2_PIX_FMT_JPEG non déclaré ici, modifiez le fichier libavdevice / v4l2-common.h et commentez les jugements de macro autour de #include <linux / videodev2.h>
// #if HAVE_SYS_VIDEOIO_H
// #include <sys/videoio.h>
// #else
// #if HAVE_ASM_TYPES_H
// #include <asm/types.h>
// #endif
#include <linux/videodev2.h>
// #endif
faire un test
root@sundata:/data/szc/ffmpeg# ldd ffmpeg
linux-vdso.so.1 (0x00007ffd3fbb1000)
libavdevice.so.58 => not found
libavfilter.so.7 => not found
libavformat.so.58 => not found
libavcodec.so.58 => not found
libpostproc.so.55 => not found
libswresample.so.3 => not found
libswscale.so.5 => not found
libavutil.so.56 => not found
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f7bf1a84000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f7bf1865000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f7bf1474000)
/lib64/ld-linux-x86-64.so.2 (0x00007f7bf2068000)
root@sundata:/data/szc/ffmpeg# ffmpeg -version
ffmpeg version 3.4.8-0ubuntu0.2 Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 7 (Ubuntu 7.5.0-3ubuntu1~18.04)
configuration: --prefix=/usr --extra-version=0ubuntu0.2 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
libavutil 55. 78.100 / 55. 78.100
libavcodec 57.107.100 / 57.107.100
libavformat 57. 83.100 / 57. 83.100
libavdevice 57. 10.100 / 57. 10.100
libavfilter 6.107.100 / 6.107.100
libavresample 3. 7. 0 / 3. 7. 0
libswscale 4. 8.100 / 4. 8.100
libswresample 2. 9.100 / 2. 9.100
libpostproc 54. 7.100 / 54. 7.100
Compilez et installez opencv3
Situation idéale
(base) root@ubuntu:/home/szc/opencv/opencv-3.0.0/build# cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
Si tout est normal, cela réussira et il y aura un Makefile dans le répertoire courant
![](https://img-blog.csdnimg.cn/20201121122801687.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM3NDc1MTY4,size_16,color_FFFFFF,t_70)
(base) root@ubuntu:/home/szc/opencv/opencv-3.0.0/build# make -j6 && make install
Le processus ci-dessus est normal sur ma machine virtuelle, et la capture d'écran après la fin est affichée ci-dessous
![](https://img-blog.csdnimg.cn/20201121122801662.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM3NDc1MTY4,size_16,color_FFFFFF,t_70)
La gestion des erreurs
Copier le fichier d'en-tête
root@sundata:/data/szc/opencv/opencv-3.0.0/build# apt-get install libpt-dev apcalc-dev linux-oracle-headers-4.15.0-1054
root@sundata:/data/szc/opencv/opencv-3.0.0/build# cp -r /usr/include/x86_64-linux-gnu/libavformat /usr/include
root@sundata:/data/szc/opencv/opencv-3.0.0/build# cp /usr/include/calc/cmath.h /usr/local/include/
root@sundata:/data/szc/opencv/opencv-3.0.0/build# cp /usr/include/c++/v1/* /usr/local/include
root@sundata:/data/szc/opencv/opencv-3.0.0/build# cp /snap/gnome-3-34-1804/36/usr/include/c++/6/cmath /usr/local/include
root@sundata:/data/szc/opencv/opencv-3.0.0/build# cp /usr/src/linux-oracle-headers-4.15.0-1054/include/uapi/linux/videodev2.h /usr/local/include/linux/
root@sundata:/data/szc/opencv/opencv-3.0.0/build# cp /usr/include/ptlib/videoio.h /usr/local/include/sys/
root@sundata:/data/szc/opencv/opencv-3.0.0/build# cp /usr/include/ptbuildopts.h /usr/local/include
root@sundata:/data/szc/opencv/opencv-3.0.0/build# cp -r /usr/include/ptlib /usr/local/include
root@sundata:/data/szc/opencv/opencv-3.0.0/build# cp /usr/include/ptlib.h /usr/local/include
root@sundata:/data/szc/opencv/opencv-3.0.0/build# cp /snap/gnome-3-34-1804/36/usr/include/c++/6/bits/cpp_type_traits.h /usr/local/include/bits
root@sundata:/data/szc/opencv/opencv-3.0.0/build# cp -r /usr/src/linux-hwe-5.4-headers-5.4.0-48/include/linux/* /usr/local/include/linux/
root@sundata:/data/szc/opencv/opencv-3.0.0/build# cp -r /usr/src/linux-hwe-5.4-headers-5.4.0-48/include/uapi /usr/local/include
root@sundata:/data/szc/opencv/opencv-3.0.0/build# cp /snap/gnome-3-34-1804/36/usr/lib/gcc/x86_64-linux-gnu/6/include/stdbool.h /usr/local/include
root@sundata:/data/szc/opencv/opencv-3.0.0/build# cp /usr/local/include/c++/6/ext/atomicity.h /usr/local/include/ext/
Notez que libpjproject-dev semble s'exclure mutuellement avec libpt-dev, donc copiez les fichiers pertinents de cette dernière dans le répertoire / usr / local / include avant d'installer ce dernier
root@sundata:/data/szc/opencv/opencv-3.0.0/build# apt-get install libpjproject-dev
root@sundata:/data/szc/opencv/opencv-3.0.0/build# cp /usr/include/pjmedia/videodev.h /usr/local/include/linux/
root@sundata:/data/szc/opencv/opencv-3.0.0/build# cp -r /usr/include/pj* /usr/local/include
Modifier le fichier d'en-tête
Certains fichiers doivent être modifiés:
#pragma once
#ifdef __cplusplus
extern "C++" {
.....
} // extern "C++"
#endif
....
2), /usr/local/include/wchar.h, ajoutez la définition de macro de wchar_t à une certaine ligne au début
....
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
#define int32 wchar_t
#include_next <wchar.h>
....
3), /usr/local/include/ptlib/unix/ptlib/contain.h, plus le fichier d'en-tête
#include <wchar.h>
- Type inconnu extern "C ++": modifiez type_traits, cmath, utilisez #ifdef __cplusplus .... #endif wrap extern "C ++" {}
- Type inconnu utilisant l'espace de noms std: modifiez ptlib / unix / ptlib / contain.h, utilisez #ifdef __cplusplus .... #endif wrap en utilisant l'espace de noms std;
- Inconnu type_LIBCPP_BEGIN_NAMESPACE_STD: modifiez atomic, cctype, cstring, cstddef, cstdio, cstdint, iosfwd, ios, iterator, cstdlib, cwctype, cwchar, memory, stdexcept, tuple, typeinfo, type_targlib, utilité, cwctype, cwchar. iostream, iomanip, map files, utilisez #ifdef __cplusplus .... #endif pour encapsuler _LIBCPP_BEGIN_NAMESPACE_STD ..... _LIBCPP_END_NAMESPACE_STD, dans lequel le fichier d'en-tête atomique #include <stdbool.h>, et Comment out #error <atomic> est non implémenté; le fichier stdexcept est du premier _LIBCPP_BEGIN_NAMESPACE_STD au dernier _LIBCPP_END_NAMESPACE_STD, essentiellement à la fin du fichier
- Espace de noms de type inconnu std: modifiez __nullptr, exception, liste_initialiseur, fichiers typeinfo, utilisez #ifdef __cplusplus .... #endif pour envelopper tout l'espace de noms std {}
- #include_next <stddef.h> Impossible de trouver le fichier stddef.h, modifiez le fichier cstddef, remplacez #include_next <stddef.h> par #include <stddef.h>
- Type inconnu _LIBCPP_PUSH_MACROS: Modify __string, __bit_reference, __mutex_base, __threading_support, __split_buffer, __tree, string_view, string, streambuf, algorithme, mémoire, limites, locale, bitset, mutex, chrono fichiers, ratio, istream, sstream ifdef __cplusplus .... #endif pour encapsuler _LIBCPP_PUSH_MACROS et _LIBCPP_BEGIN_NAMESPACE_STD ..... _LIBCPP_POP_MACROS
- nouveau fichier:
- Utilisez #ifdef __cplusplus .... #endif pour encapsuler le contenu entre #if! Defined (_LIBCPP_ABI_MICROSOFT) || defined (_LIBCPP_NO_VCRUNTIME) .... # endif //! _LIBCPP_ABI_MICROSOFT || _LIBCPP_NO_VCRUNTIME
- Utilisez #ifdef __cplusplus .... #endif pour encapsuler _LIBCPP_BEGIN_NAMESPACE_STD ..... _LIBCPP_END_NAMESPACE_STD
- Fichier __functional_base: utilisez #ifdef __cplusplus .... #endif pour encapsuler _LIBCPP_BEGIN_NAMESPACE_STD ..... _LIBCPP_END_NAMESPACE_STD et constexpr
- Fichier ext / atomicity.h: utilisez #ifdef __cplusplus .... #endif pour envelopper l'espace de noms
- ptlib / directory: Il y a beaucoup de fichiers à modifier, vous pouvez télécharger les modifiés directement depuis mon disque réseau: lien: https://pan.baidu.com/s/1guHSn6iVRGyrw8enXead5Q , code d'extraction: hsw3
- Fichier sys / videoio.h: Utilisez #ifdef __cplusplus .... #endif pour encapsuler la classe PColourConverter; ...... class PVideoFont: contenu PObject public entre les deux classes
- class: modifiez le fichier __debug, enveloppez la classe avec #ifdef __cplusplus .... #endif _LIBCPP_EXCEPTION_ABI __libcpp_debug_exception;
Modifier le fichier OpenCV
Les fichiers suivants se trouvent dans le répertoire de opencv3.0.0
#include <cuda_fp16.h>
2 cmake / FindCUDA.cmake
find_cuda_helper_libs(nppi)
À
find_cuda_helper_libs(nppial)
find_cuda_helper_libs(nppicc)
find_cuda_helper_libs(nppicom)
find_cuda_helper_libs(nppidei)
find_cuda_helper_libs(nppif)
find_cuda_helper_libs(nppig)
find_cuda_helper_libs(nppim)
find_cuda_helper_libs(nppist)
find_cuda_helper_libs(nppisu)
find_cuda_helper_libs(nppitc)
alors:
set(CUDA_npp_LIBRARY "${CUDA_nppc_LIBRARY};${CUDA_nppi_LIBRARY};${CUDA_npps_LIBRARY}")
À
set(CUDA_npp_LIBRARY "${CUDA_nppc_LIBRARY};${CUDA_nppial_LIBRARY};${CUDA_nppicc_LIBRARY};${CUDA_nppicom_LIBRARY};${CUDA_nppidei_LIBRARY};${CUDA_nppif_LIBRARY};${CUDA_nppig_LIBRARY};${CUDA_nppim_LIBRARY};${CUDA_nppist_LIBRARY};${CUDA_nppisu_LIBRARY};${CUDA_nppitc_LIBRARY};${CUDA_npps_LIBRARY}")
Enfin:
unset(CUDA_nppi_LIBRARY CACHE)
À
unset(CUDA_nppial_LIBRARY CACHE)
unset(CUDA_nppicc_LIBRARY CACHE)
unset(CUDA_nppicom_LIBRARY CACHE)
unset(CUDA_nppidei_LIBRARY CACHE)
unset(CUDA_nppif_LIBRARY CACHE)
unset(CUDA_nppig_LIBRARY CACHE)
unset(CUDA_nppim_LIBRARY CACHE)
unset(CUDA_nppist_LIBRARY CACHE)
unset(CUDA_nppisu_LIBRARY CACHE)
unset(CUDA_nppitc_LIBRARY CACHE)
3 cmake / OpenCVDetectCUDA.cmake
if(CUDA_GENERATION STREQUAL "Fermi")
set(__cuda_arch_bin "2.0 2.1(2.0)")
elseif(CUDA_GENERATION STREQUAL "Kepler")
if(${CUDA_VERSION} VERSION_LESS "5.0")
set(__cuda_arch_bin "3.0")
else()
set(__cuda_arch_bin "3.0 3.5")
endif()
À
if(CUDA_GENERATION STREQUAL "Kepler")
set(__cuda_arch_bin "3.0 3.5 3.7")
elseif(CUDA_GENERATION STREQUAL "Maxwell")
set(__cuda_arch_bin "5.0 5.2")
4 cmake / OpenCVFindLibsVideo.cmake
CHECK_INCLUDE_FILE(ffmpeg/avformat.h HAVE_FFMPEG_FFMPEG)
CHECK_INCLUDE_FILE(libavformat/avformat.h HAVE_FFMPEG_FFMPEG)
if(EXISTS /usr/include/ffmpeg/libavformat/avformat.h OR HAVE_FFMPEG_SWSCALE)
if(EXISTS /usr/local/include/libavformat/avformat.h OR HAVE_FFMPEG_SWSCALE)
# ----------------------------------------------------------------------------
# Detect Microsoft compiler:
# ----------------------------------------------------------------------------
if(CMAKE_CL_64)
set(MSVC64 1)
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(CMAKE_COMPILER_IS_GNUCXX 1)
set(CMAKE_COMPILER_IS_CLANGCXX 1)
endif()
if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
set(CMAKE_COMPILER_IS_GNUCC 1)
set(CMAKE_COMPILER_IS_CLANGCC 1)
endif()
if("${CMAKE_CXX_COMPILER};${CMAKE_C_COMPILER}" MATCHES "ccache")
set(CMAKE_COMPILER_IS_CCACHE 1)
endif()
# ----------------------------------------------------------------------------
# Detect Intel ICC compiler -- for -fPIC in 3rdparty ( UNIX ONLY ):
# see include/opencv/cxtypes.h file for related ICC & CV_ICC defines.
# NOTE: The system needs to determine if the '-fPIC' option needs to be added
# for the 3rdparty static libs being compiled. The CMakeLists.txt files
# in 3rdparty use the CV_ICC definition being set here to determine if
# the -fPIC flag should be used.
# ----------------------------------------------------------------------------
if(UNIX)
if (__ICL)
set(CV_ICC __ICL)
elseif(__ICC)
set(CV_ICC __ICC)
elseif(__ECL)
set(CV_ICC __ECL)
elseif(__ECC)
set(CV_ICC __ECC)
elseif(__INTEL_COMPILER)
set(CV_ICC __INTEL_COMPILER)
elseif(CMAKE_C_COMPILER MATCHES "icc")
set(CV_ICC icc_matches_c_compiler)
endif()
endif()
if(MSVC AND CMAKE_C_COMPILER MATCHES "icc|icl")
set(CV_ICC __INTEL_COMPILER_FOR_WINDOWS)
endif()
# ----------------------------------------------------------------------------
# Detect GNU version:
# ----------------------------------------------------------------------------
if(CMAKE_COMPILER_IS_CLANGCXX)
set(CMAKE_GCC_REGEX_VERSION "4.2.1")
set(CMAKE_OPENCV_GCC_VERSION_MAJOR 4)
set(CMAKE_OPENCV_GCC_VERSION_MINOR 2)
set(CMAKE_OPENCV_GCC_VERSION 42)
set(CMAKE_OPENCV_GCC_VERSION_NUM 402)
execute_process(COMMAND ${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1} -v
ERROR_VARIABLE CMAKE_OPENCV_CLANG_VERSION_FULL
ERROR_STRIP_TRAILING_WHITESPACE)
string(REGEX MATCH "version.*$" CMAKE_OPENCV_CLANG_VERSION_FULL "${CMAKE_OPENCV_CLANG_VERSION_FULL}")
string(REGEX MATCH "[0-9]+\\.[0-9]+" CMAKE_CLANG_REGEX_VERSION "${CMAKE_OPENCV_CLANG_VERSION_FULL}")
elseif(CMAKE_COMPILER_IS_GNUCXX)
execute_process(COMMAND ${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1} -dumpversion
OUTPUT_VARIABLE CMAKE_OPENCV_GCC_VERSION_FULL
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1} -v
ERROR_VARIABLE CMAKE_OPENCV_GCC_INFO_FULL
OUTPUT_STRIP_TRAILING_WHITESPACE)
# Typical output in CMAKE_OPENCV_GCC_VERSION_FULL: "c+//0 (whatever) 4.2.3 (...)"
# Look for the version number, major.minor.build
string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" CMAKE_GCC_REGEX_VERSION "${CMAKE_OPENCV_GCC_VERSION_FULL}")
if(NOT CMAKE_GCC_REGEX_VERSION)#major.minor
string(REGEX MATCH "[0-9]+\\.[0-9]+" CMAKE_GCC_REGEX_VERSION "${CMAKE_OPENCV_GCC_VERSION_FULL}")
endif()
if(CMAKE_GCC_REGEX_VERSION)
# Split the parts:
string(REGEX MATCHALL "[0-9]+" CMAKE_OPENCV_GCC_VERSIONS "${CMAKE_GCC_REGEX_VERSION}")
list(GET CMAKE_OPENCV_GCC_VERSIONS 0 CMAKE_OPENCV_GCC_VERSION_MAJOR)
list(GET CMAKE_OPENCV_GCC_VERSIONS 1 CMAKE_OPENCV_GCC_VERSION_MINOR)
else()#compiler returned just the major version number
string(REGEX MATCH "[0-9]+" CMAKE_GCC_REGEX_VERSION "${CMAKE_OPENCV_GCC_VERSION_FULL}")
if(NOT CMAKE_GCC_REGEX_VERSION)#compiler did not return anything reasonable
set(CMAKE_GCC_REGEX_VERSION "0")
message(WARNING "GCC version not detected!")
endif()
set(CMAKE_OPENCV_GCC_VERSION_MAJOR ${CMAKE_GCC_REGEX_VERSION})
set(CMAKE_OPENCV_GCC_VERSION_MINOR 0)
endif()
set(CMAKE_OPENCV_GCC_VERSION ${CMAKE_OPENCV_GCC_VERSION_MAJOR}${CMAKE_OPENCV_GCC_VERSION_MINOR})
math(EXPR CMAKE_OPENCV_GCC_VERSION_NUM "${CMAKE_OPENCV_GCC_VERSION_MAJOR}*100 + ${CMAKE_OPENCV_GCC_VERSION_MINOR}")
message(STATUS "Detected version of GNU GCC: ${CMAKE_OPENCV_GCC_VERSION} (${CMAKE_OPENCV_GCC_VERSION_NUM})")
if(WIN32)
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpmachine
OUTPUT_VARIABLE OPENCV_GCC_TARGET_MACHINE
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(OPENCV_GCC_TARGET_MACHINE MATCHES "amd64|x86_64|AMD64")
set(MINGW64 1)
endif()
endif()
endif()
if(MSVC64 OR MINGW64)
set(X86_64 1)
elseif(MINGW OR (MSVC AND NOT CMAKE_CROSSCOMPILING))
set(X86 1)
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "amd64.*|x86_64.*|AMD64.*")
set(X86_64 1)
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "i686.*|i386.*|x86.*|amd64.*|AMD64.*")
set(X86 1)
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm.*|ARM.*)")
set(ARM 1)
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64.*|AARCH64.*)")
set(AARCH64 1)
endif()
# Workaround for 32-bit operating systems on 64-bit x86_64 processor
if(X86_64 AND CMAKE_SIZEOF_VOID_P EQUAL 4 AND NOT FORCE_X86_64)
message(STATUS "sizeof(void) = 4 on x86 / x86_64 processor. Assume 32-bit compilation mode (X86=1)")
unset(X86_64)
set(X86 1)
endif()
# Similar code exists in OpenCVConfig.cmake
if(NOT DEFINED OpenCV_STATIC)
# look for global setting
if(NOT DEFINED BUILD_SHARED_LIBS OR BUILD_SHARED_LIBS)
set(OpenCV_STATIC OFF)
else()
set(OpenCV_STATIC ON)
endif()
endif()
if(MSVC)
if(CMAKE_CL_64)
set(OpenCV_ARCH x64)
elseif((CMAKE_GENERATOR MATCHES "ARM") OR ("${arch_hint}" STREQUAL "ARM") OR (CMAKE_VS_EFFECTIVE_PLATFORMS MATCHES "ARM|arm"))
# see Modules/CmakeGenericSystem.cmake
set(OpenCV_ARCH ARM)
else()
set(OpenCV_ARCH x86)
endif()
if(MSVC_VERSION EQUAL 1400)
set(OpenCV_RUNTIME vc8)
elseif(MSVC_VERSION EQUAL 1500)
set(OpenCV_RUNTIME vc9)
elseif(MSVC_VERSION EQUAL 1600)
set(OpenCV_RUNTIME vc10)
elseif(MSVC_VERSION EQUAL 1700)
set(OpenCV_RUNTIME vc11)
elseif(MSVC_VERSION EQUAL 1800)
set(OpenCV_RUNTIME vc12)
elseif(MSVC_VERSION EQUAL 1900)
set(OpenCV_RUNTIME vc14)
elseif(MSVC_VERSION EQUAL 1910)
set(OpenCV_RUNTIME vc15)
endif()
elseif(MINGW)
set(OpenCV_RUNTIME mingw)
if(MINGW64)
set(OpenCV_ARCH x64)
else()
set(OpenCV_ARCH x86)
endif()
endif()
6) Si une erreur est signalée Modules demandés non disponibles: vtkRenderingOpenGL, puis modifiez le fichier /cmake/OpenCVDetectVTK.cmake, et changez
find_package(VTK QUIET COMPONENTS vtkRenderingOpenGL vtkInteractionStyle vtkRenderingLOD vtkIOPLY vtkFiltersTexture vtkRenderingFreeType vtkIOExport NO_MODULE)
Changer pour
find_package(VTK QUIET COMPONENTS vtkRenderingOpenGL2 vtkInteractionStyle vtkRenderingLOD vtkIOPLY vtkFiltersTexture vtkRenderingFreeType vtkIOExport NO_MODULE)
7) Si une erreur est signalée comme une architecture gpu non prise en charge compute_20, car mon cuda est 10.0, je dois d'abord modifier le fichier cmake / OpenCVDetectCUDA.cmake et ajouter Pascal après avoir défini _generations
set(_generations "Fermi" "Kepler" "Pascal")
Supposons alors la puissance de calcul (6.0 et 6.1) correspondant à Pascal dans la branche de jugement de CUDA_GENERATION
if(CUDA_GENERATION STREQUAL "Kepler")
set(__cuda_arch_bin "3.0 3.5 3.7")
elseif(CUDA_GENERATION STREQUAL "Maxwell")
set(__cuda_arch_bin "5.0 5.2")
elseif(CUDA_GENERATION STREQUAL "Pascal")
set(__cuda_arch_bin "6.0 6.1")
Enfin, l'architecture CUDA est spécifiée lors de la compilation de cmake
-D CUDA_GENERATION=Pascal
Modifier la méthode de fichier
Enfin, parlez des solutions à ces problèmes:
root@sundata:/home/sundata# locate bits/cpp_type_traits.h
/snap/gnome-3-34-1804/36/usr/include/c++/6/bits/cpp_type_traits.h
/usr/include/c++/3.4/bits/cpp_type_traits.h
/usr/include/c++/5/bits/cpp_type_traits.h
/usr/include/c++/7/bits/cpp_type_traits.h
/usr/local/include/c++/6/bits/cpp_type_traits.h
Ensuite, trouvez-en un et copiez-le dans le répertoire / usr / local / include (bits / cpp_type_traits.h ne se trouve pas ici, alors copiez-le dans le répertoire / usr / local / include / bits)
root@sundata:/data/szc/opencv/opencv-3.0.0/build# cp /snap/gnome-3-34-1804/36/usr/include/c++/6/bits/cpp_type_traits.h /usr/local/include/bits
S'il ne peut pas être trouvé localement, cela signifie que nous devons ajouter ce fichier en installant une bibliothèque tierce (telle que sys / videoio.h). Utilisez d'abord apt-file (installez avec apt-get si vous ne l'avez pas) pour vérifier quelle bibliothèque tierce contient ce fichier d'en-tête et le chemin où il se trouve après l'installation
root@sundata:/home/sundata# apt-file search videoio.h
libopencv-videoio-dev: /usr/include/opencv2/videoio.hpp
libopencv-videoio-dev: /usr/include/opencv2/videoio/videoio.hpp
libpt-dev: /usr/include/ptlib/videoio.h
opencv-doc: /usr/share/doc/opencv-doc/html/dd/de7/group__videoio.html
opencv-doc: /usr/share/doc/opencv-doc/html/df/d2c/tutorial_table_of_content_videoio.html
Nous devons choisir le fichier d'en-tête, donc seule libpt-dev peut choisir. Après l'installation avec apt-get, copiez ce fichier du chemin après l'installation dans / usr / local / include (car sys / videoio.h ne peut pas être trouvé, nous devons donc le copier dans le répertoire usr / local / include / sys / )
root@sundata:/data/szc/opencv/opencv-3.0.0/build# cp /usr/include/ptlib/videoio.h /usr/local/include/sys/
2), un champ est introuvable, il a été utilisé avant la définition
/* The fallback definitions, for when __WCHAR_MAX__ or __WCHAR_MIN__
are not defined, give the right value and type as long as both int
and wchar_t are 32-bit types. Adding L'\0' to a constant value
ensures that the type is correct; it is necessary to use (L'\0' +
0) rather than just L'\0' so that the type in C++ is the promoted
version of wchar_t rather than the distinct wchar_t type itself.
Because wchar_t in preprocessor #if expressions is treated as
intmax_t or uintmax_t, the expression (L'\0' - 1) would have the
wrong value for WCHAR_MAX in such expressions and so cannot be used
to define __WCHAR_MAX in the unsigned case. */
Il indique que si __WCHAR_MAX__ ou __WCHAR_MIN__ n'est pas défini, tant que wchar_t et int sont tous les deux de type 32 bits, __WCHAR_MAX__ ou __WCHAR_MIN__ sera correctement attribué et wchar_t n'a pas été attribué dans la version C ++ mise à niveau. Ensuite, j'ai dû l'aider à définir wchar_t, 32 bits, il y a donc une modification pour modifier la deuxième partie du fichier d'en-tête
Une meilleure solution - changer la version d'OpenCV
3.4.1 version d'OpenCV et d'OpenCV_contrib
Télécharger le fichier source de xfeatures2d
Modifier le fichier OpenCV
...
include_directories("modules")
# ----------------------------------------------------------------------------
# Path for build/platform -specific headers
# ----------------------------------------------------------------------------
....
2) Modifiez le CMakeLists.txt dans le répertoire du fichier opencv-3.4.1 / modules / stitching et ajoutez une phrase:
include_directories("/home/rtlab/szc/opencv-3.4.1/modules/features2d/include/")
Compiler et installer
Ensuite, utilisez la ligne de commande pour compiler et installer
root@rtlab-computer:/home/rtlab/szc/opencv-3.4.1/build# make -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D ENABLE_PRECOMPILED_HEADERS=OFF -D CUDA_GENERATION=Pascal -D OPENCV_EXTRA_MODULES_PATH=/home/rtlab/szc/opencv_contrib-3.4.1/modules -D WITH_CUDA=ON -D WITH_OPENCL=ON ..
root@rtlab-computer:/home/rtlab/szc/opencv-3.4.1/build# make -j10 && make install
La compilation est très fluide en ce moment
Configuration
include /usr/local/lib
2), modifiez / etc / profile
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
3), activer
(base) root@ubuntu:/home/szc/opencv/opencv-3.0.0/build# ldconfig
(base) root@ubuntu:/home/szc/opencv/opencv-3.0.0/build# source /etc/profile
test
root@ubuntu:/home/szc/opencv/opencv-3.0.0/build# pkg-config opencv --modversion
Si le numéro de version peut être affiché correctement, il réussira
![](https://img-blog.csdnimg.cn/20201121122801673.png)
Conclusion
Lors du choix de la version OpenCV à compiler et à installer, il est préférable de vérifier si votre version CUDA est incluse dans le fichier cmake / OpenCVDetectCUDA.cmake dans github (par exemple, Pascal avec une puissance de calcul de 6.X), afin que vous peut éviter de nombreux détours. De plus, certains cas de test dans OpenCV ne peuvent pas être exécutés en raison d'un manque de données; d'autres ne peuvent pas être exécutés pour diverses raisons, mais tant que le numéro de version peut être affiché correctement, cela devrait indiquer que notre installation est réussie.