【发布时间】:2020-08-11 12:00:55
【问题描述】:
所以,几天来我一直在努力让 opencv 支持 nvidia gpu,但无法让 python 导入 cv2(导入预编译的 opencv-python 可以按预期工作)。出于沮丧,我刚刚删除然后解压缩了 opencv_contrib_master,令我惊讶的是,CMake 中弹出了几行新行:
在未分组的条目下:
BUILD_OPENCV_CUDA
在 Python 3 下:
install path: C:/ProgramData/Anaconda3/Lib/site-packages/cv2/python-3.7
OpenCV 下:
OPENCV_PYTHON3_VERSION
太好了。进步。但是现在出现了一个新的敌人:
CMake Warning at cmake/OpenCVGenSetupVars.cmake:54 (message):
CONFIGURATION IS NOT SUPPORTED: validate setupvars script in install
directory
Call Stack (most recent call first):
CMakeLists.txt:967 (include)
here 提到了上述错误,并指出该错误与 python 配置有关。我认为 PY3 配置看起来不错:
PYTHON3_EXECUTABLE C:/ProgramData/Anaconda3/python.exe
PYTHON3_INCLUDE_DIR C:/ProgramData/Anaconda3/include
PYTHON3_INCLUDE_DIR2
PYTHON3_LIBRARY C:/ProgramData/Anaconda3/libs/python37.lib
PYTHON3_LIBRARY_DEBUG PYTHON_DEBUG_LIBRARY-NOTFOUND
PYTHON3_NUMPY_INCLUDE_DIRS C:/ProgramData/Anaconda3/Lib/site-packages/numpy/core/include
PYTHON3_PACKAGE_PATH C:/ProgramData/Anaconda3/Lib/site-packages
编辑 10:在随后的安装中,我看到 Cmake 从 User/Roaming 而不是 ProgramData/Anaconda3 进入 numpy 库。我不知道差异是否会影响构建成功。
我注意到这些都不见了(不确定是否重要):
CUDA_nvToolsExt_LIBRARY-NOTFOUND
CUDA_nvcuvenc_LIBRARY-NOTFOUND
CUDA_nvcuvid_LIBRARY-NOTFOUND
与 BLAS/LAPLACK/EIGEN 一起。我仍然不清楚这些对于 python 句柄是否必要。
使用 GTX 1080,所以我只保留了 gpu arch 6.1 版本。省略其他版本将构建时间从 2 小时 15 分钟缩短到约 30 分钟:
Pascal (CUDA 8 and later)
SM60 or SM_60, compute_60 – Quadro GP100, Tesla P100, DGX-1 (Generic Pascal)
SM61 or SM_61, compute_61 – GTX 1080, GTX 1070, GTX
来自 CMake 的完整构建规范:
Selecting Windows SDK version 10.0.18362.0 to target Windows 10.0.18363.
Detected processor: AMD64
libjpeg-turbo: VERSION = 2.0.4, BUILD = opencv-4.3.0-dev-libjpeg-turbo
Found OpenJPEG: openjp2 (found version "2.3.0")
found Intel IPP (ICV version): 2020.0.0 [2020.0.0 Gold]
at: C:/Users/---/Downloads/opencv-master/build/3rdparty/ippicv/ippicv_win/icv
found Intel IPP Integration Wrappers sources: 2020.0.0
at: C:/Users/---/Downloads/opencv-master/build/3rdparty/ippicv/ippicv_win/iw
CUDA detected: 10.0
CUDA NVCC target flags: -gencode;arch=compute_61,code=sm_61;-D_FORCE_INLINES
Could NOT find JNI (missing: JAVA_AWT_LIBRARY JAVA_JVM_LIBRARY JAVA_INCLUDE_PATH JAVA_INCLUDE_PATH2 JAVA_AWT_INCLUDE_PATH)
VTK is not found. Please set -DVTK_DIR in CMake to VTK build directory, or to VTK install subdirectory with VTKConfig.cmake file
OpenCV Python: during development append to PYTHONPATH: C:/Users/---/Downloads/opencv-master/build/python_loader
Module opencv_alphamat disabled because the following dependencies are not found: Eigen
Caffe: NO
Protobuf: NO
Glog: NO
freetype2: NO
harfbuzz: NO
Module opencv_ovis disabled because OGRE3D was not found
No preference for use of exported gflags CMake configuration set, and no hints for include/library directories provided. Defaulting to preferring an installed/exported gflags CMake configuration if available.
Failed to find installed gflags CMake configuration, searching for gflags build directories exported with CMake.
Failed to find gflags - Failed to find an installed/exported CMake configuration for gflags, will perform search for installed gflags components.
Failed to find gflags - Could not find gflags include directory, set GFLAGS_INCLUDE_DIR to directory containing gflags/gflags.h
Failed to find glog - Could not find glog include directory, set GLOG_INCLUDE_DIR to directory containing glog/logging.h
Module opencv_sfm disabled because the following dependencies are not found: Eigen Glog/Gflags
Tesseract: NO
Allocator metrics storage type: 'long long'
Registering hook 'INIT_MODULE_SOURCES_opencv_dnn': C:/Users/---/Downloads/opencv-master/modules/dnn/cmake/hooks/INIT_MODULE_SOURCES_opencv_dnn.cmake
CMake Warning at cmake/OpenCVGenSetupVars.cmake:54 (message):
CONFIGURATION IS NOT SUPPORTED: validate setupvars script in install
directory
Call Stack (most recent call first):
CMakeLists.txt:967 (include)
General configuration for OpenCV 4.3.0-dev =====================================
Version control: unknown
Extra modules:
Location (extra): C:/Users/---/Downloads/opencv_contrib-master/modules
Version control (extra): unknown
Platform:
Timestamp: 2020-04-27T18:31:30Z
Host: Windows 10.0.18363 AMD64
CMake: 3.17.1
CMake generator: Visual Studio 15 2017
CMake build tool: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/MSBuild/15.0/Bin/MSBuild.exe
MSVC: 1916
CPU/HW features:
Baseline: SSE SSE2 SSE3
requested: SSE3
Dispatched code generation: SSE4_1 SSE4_2 FP16 AVX AVX2 AVX512_SKX
requested: SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
SSE4_1 (16 files): + SSSE3 SSE4_1
SSE4_2 (2 files): + SSSE3 SSE4_1 POPCNT SSE4_2
FP16 (1 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
AVX (5 files): + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
AVX2 (30 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
AVX512_SKX (6 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2 AVX_512F AVX512_COMMON AVX512_SKX
C/C++:
Built as dynamic libs?: YES
C++ standard: 11
C++ Compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x64/cl.exe (ver 19.16.27039.0)
C++ flags (Release): /DWIN32 /D_WINDOWS /W4 /GR /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi /fp:precise /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 /MP /MD /O2 /Ob2 /DNDEBUG
C++ flags (Debug): /DWIN32 /D_WINDOWS /W4 /GR /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi /fp:precise /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 /MP /MDd /Zi /Ob0 /Od /RTC1
C Compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x64/cl.exe
C flags (Release): /DWIN32 /D_WINDOWS /W3 /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi /fp:precise /MP /MD /O2 /Ob2 /DNDEBUG
C flags (Debug): /DWIN32 /D_WINDOWS /W3 /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi /fp:precise /MP /MDd /Zi /Ob0 /Od /RTC1
Linker flags (Release): /machine:x64 /INCREMENTAL:NO
Linker flags (Debug): /machine:x64 /debug /INCREMENTAL
ccache: NO
Precompiled headers: YES
Extra dependencies: cudart_static.lib nppc.lib nppial.lib nppicc.lib nppicom.lib nppidei.lib nppif.lib nppig.lib nppim.lib nppist.lib nppisu.lib nppitc.lib npps.lib cublas.lib cudnn.lib cufft.lib -LIBPATH:C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.0/lib/x64 -LIBPATH:C:/Users/---/Downloads/cudnn-10.0-windows10-x64-v7.6.5.32/cuda/lib/x64
3rdparty dependencies:
OpenCV modules:
To be built: aruco bgsegm bioinspired calib3d ccalib core cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev datasets dnn dnn_objdetect dnn_superres dpm face features2d flann fuzzy gapi hdf hfs highgui img_hash imgcodecs imgproc intensity_transform line_descriptor ml objdetect optflow phase_unwrapping photo plot python3 pythoncuda quality rapid reg rgbd saliency shape stereo stitching structured_light superres surface_matching text tracking ts video videoio videostab xfeatures2d ximgproc xobjdetect xphoto
Disabled: world (i have this enabled in another attempt- and included it in env path)
Disabled by dependency: -
Unavailable: alphamat cnn_3dobj cvv freetype java js matlab ovis python2 sfm viz
Applications: tests perf_tests apps
Documentation: NO
Non-free algorithms: NO
Windows RT support: NO
GUI:
Win32 UI: YES
VTK support: NO
Media I/O:
ZLib: build (ver 1.2.11)
JPEG: build-libjpeg-turbo (ver 2.0.4-62)
WEBP: build (ver encoder: 0x020f)
PNG: build (ver 1.6.37)
TIFF: build (ver 42 - 4.0.10)
JPEG 2000: OpenJPEG (ver 2.3.0)
OpenEXR: build (ver 2.3.0)
HDR: YES
SUNRASTER: YES
PXM: YES
PFM: YES
Video I/O:
DC1394: NO
FFMPEG: YES (prebuilt binaries)
avcodec: YES (58.54.100)
avformat: YES (58.29.100)
avutil: YES (56.31.100)
swscale: YES (5.5.100)
avresample: YES (4.0.0)
GStreamer: NO
DirectShow: YES
Media Foundation: YES
DXVA: YES
Parallel framework: Concurrency
Trace: YES (with Intel ITT)
Other third-party libraries:
Intel IPP: 2020.0.0 Gold [2020.0.0]
at: C:/Users/---/Downloads/opencv-master/build/3rdparty/ippicv/ippicv_win/icv
Intel IPP IW: sources (2020.0.0)
at: C:/Users/---/Downloads/opencv-master/build/3rdparty/ippicv/ippicv_win/iw
Eigen: NO
Custom HAL: NO
Protobuf: build (3.5.1)
NVIDIA CUDA: YES (ver 10.0, CUFFT CUBLAS FAST_MATH)
NVIDIA GPU arch: 61
NVIDIA PTX archs:
cuDNN: YES (ver 7.6.5)
OpenCL: YES (NVD3D11)
Include path: C:/Users/---/Downloads/opencv-master/3rdparty/include/opencl/1.2
Link libraries: Dynamic load
Python 3:
Interpreter: C:/ProgramData/Anaconda3/python.exe (ver 3.7.7)
Libraries: C:/ProgramData/Anaconda3/libs/python37.lib (ver 3.7.7)
numpy: C:/ProgramData/Anaconda3/Lib/site-packages/numpy/core/include (ver 1.15.0)
install path: C:/ProgramData/Anaconda3/Lib/site-packages/cv2/python-3.7
Python (for build): C:/ProgramData/Anaconda3/python.exe
Java:
ant: NO
JNI: NO
Java wrappers: NO
Java tests: NO
Install to: C:/Users/---/Downloads/opencv-master/build/install
-----------------------------------------------------------------
Configuring done
我错过了什么吗?救命!
编辑: These messages now pop up after Visual Studio Build
edit2:现在在 INSTALL 构建中得到这个: C:\Users---\Downloads\opencv-master\build\modules\highgui\opencv_highgui.vcxproj:错误:无法加载项目文件。根级别的数据无效。第 260 行,位置 11。C:\Users---\Downloads\opencv-master\build\modules\highgui\opencv_highgui.vcxproj
编辑3: 我删除并解压缩了 opencv-master 以重新开始,现在在 CMake 配置上我得到:
CMake Error at modules/videoio/cmake/detect_ffmpeg.cmake:16 (include):
include could not find load file:
C:/Users/---/Downloads/opencv-master/build/3rdparty/ffmpeg/ffmpeg_version.cmake
Call Stack (most recent call first):
modules/videoio/cmake/init.cmake:3 (include)
modules/videoio/cmake/init.cmake:22 (add_backend)
cmake/OpenCVModule.cmake:312 (include)
cmake/OpenCVModule.cmake:375 (_add_modules_1)
modules/CMakeLists.txt:7 (ocv_glob_modules)
CMake Warning at C:/Users/---/Downloads/opencv-master/cmake/OpenCVModule.cmake:679 (message):
Unexpected include:
C:/Users/---/Downloads/opencv-master/build/downloads/xfeatures2d
(module=opencv_xfeatures2d)
Call Stack (most recent call first):
C:/Users/---/Downloads/opencv-master/cmake/OpenCVModule.cmake:710 (ocv_target_include_modules)
C:/Users/---/Downloads/opencv_contrib-master/modules/xfeatures2d/CMakeLists.txt:17 (ocv_module_include_directories)
CMake Warning at cmake/OpenCVGenSetupVars.cmake:54 (message):
CONFIGURATION IS NOT SUPPORTED: validate setupvars script in install
directory
Call Stack (most recent call first):
CMakeLists.txt:967 (include)
编辑4: 删除了 opencv-master/opencv-contrib-master 并重新运行 CMake。当我第一次配置 CMake 时,我注意到了这个警告。可能与上面的配置错误有关...?
CMake Warning at cmake/OpenCVDetectPython.cmake:81 (message):
CMake's 'find_host_package(PythonInterp 2.7)' found wrong Python version:
PYTHON_EXECUTABLE=C:/ProgramData/Anaconda3/python.exe
PYTHON_VERSION_STRING=3.7.7
Consider providing the 'PYTHON2_EXECUTABLE' variable via CMake command line
or environment variables
Call Stack (most recent call first):
cmake/OpenCVDetectPython.cmake:271 (find_python)
CMakeLists.txt:598 (include)
编辑 5: Visual Studio 输出:
CMake Error at modules/python3/cmake_install.cmake:93 (file):
197> file INSTALL cannot find
197> "C:/Users/---/Documents/opencv_folder/opencv-master/opencv-master/build/lib/python3/Release/cv2.cp37-win_amd64.pyd":
197> File exists.
197>Call Stack (most recent call first):
197> modules/cmake_install.cmake:192 (include)
197> cmake_install.cmake:120 (include)
来自 anaconda CLI:
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\ProgramData\Anaconda3\lib\cv2\__init__.py", line 96, in <module>
bootstrap()
File "C:\ProgramData\Anaconda3\lib\cv2\__init__.py", line 62, in bootstrap
], True)
File "C:\ProgramData\Anaconda3\lib\cv2\__init__.py", line 56, in load_first_config
raise ImportError('OpenCV loader: missing configuration file: {}. Check OpenCV installation.'.format(fnames))
ImportError: OpenCV loader: missing configuration file: ['config-3.7.py', 'config-3.py']. Check OpenCV installation.
编辑 6: Visual Studio 完成了一次构建(再次为 x8),没有任何错误。
>>> import cv2
['', 'C:\\ProgramData\\Anaconda3\\python.exe', 'C:\\ProgramData\\Anaconda3\\python37.zip', 'C:\\ProgramData\\Anaconda3\\DLLs', 'C:\\ProgramData\\Anaconda3\\lib', 'C:\\ProgramData\\Anaconda3', 'C:\\Users\\---\\AppData\\Roaming\\Python\\Python37\\site-packages', 'C:\\ProgramData\\Anaconda3\\lib\\site-packages', 'C:\\ProgramData\\Anaconda3\\lib\\site-packages\\win32', 'C:\\ProgramData\\Anaconda3\\lib\\site-packages\\win32\\lib', 'C:\\ProgramData\\Anaconda3\\lib\\site-packages\\Pythonwin']
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\ProgramData\Anaconda3\lib\cv2\__init__.py", line 96, in <module>
bootstrap()
File "C:\ProgramData\Anaconda3\lib\cv2\__init__.py", line 23, in bootstrap
raise ImportError('ERROR: recursion is detected during loading of "cv2" binary extensions. Check OpenCV installation.')
ImportError: ERROR: recursion is detected during loading of "cv2" binary extensions. Check OpenCV installation.
从“C:\ProgramData\Anaconda3\Lib”中删除 cv2 会导致找不到模块错误。 从“C:\ProgramData\Anaconda3\Lib\Site-Packages”中删除 cv2 会创建 dll 错误。 删除两者都会稍微增加我在此设置上花费的小时数。
我在启用和禁用 cv2world 的情况下进行编译,并在 env 路径中设置 cv2world.dll 并复制到 ProgramData\Anaconda\Lib。
编辑 7: 我曾经分区的所有 R 环境都损坏了,我的计算机现在运行很差(无论大小如何,在传输文件时,explorer 都会卡在 99% 上;显着增加了启动时间)。现在有一个错误的 Python3.6 安装。可能是时候重新安装 Windows 了。
编辑 8:
import cv2
Traceback (most recent call last):
File "<ipython-input-1-c8ec22b3e787>", line 1, in <module>
import cv2
File "C:\Users\Arman\AppData\Roaming\Python\Python37\site-packages\cv2\__init__.py", line 89, in <module>
bootstrap()
File "C:\Users\Arman\AppData\Roaming\Python\Python37\site-packages\cv2\__init__.py", line 62, in bootstrap
], True)
File "C:\Users\Arman\AppData\Roaming\Python\Python37\site-packages\cv2\__init__.py", line 56, in load_first_config
raise ImportError('OpenCV loader: missing configuration file: {}. Check OpenCV installation.'.format(fnames))
ImportError: OpenCV loader: missing configuration file: ['config-3.7.py', 'config-3.py']. Check OpenCV installation.
我尝试了 ctrl+cv 配置文件,但将错误更改为 recursion 之一。目前还没有与 cuda 一起工作的 opencv。
编辑 9: 仍然没有模块被导出到 Anaconda 库。
可能跟这个有关:Opencv fatal error LNK1120: 143 unresolved externals
opencv-folder\opencv-master\build\bin\Release\opencv_world430.dll : fatal error LNK1120: 143 unresolved externals
25>Done building project "opencv_world.vcxproj" -- FAILED.
26>------ Build started: Project: opencv_ts, Configuration: Release x64 ------
27>------ Build started: Project: opencv_img_hash, Configuration: Release x64 ------
28>------ Build started: Project: opencv_waldboost_detector, Configuration: Release x64 ------
29>------ Build started: Project: opencv_annotation, Configuration: Release x64 ------
30>------ Build started: Project: opencv_interactive-calibration, Configuration: Release x64 ------
31>------ Build started: Project: opencv_version, Configuration: Release x64 ------
32>------ Build started: Project: opencv_version_win32, Configuration: Release x64 ------
33>------ Build started: Project: opencv_visualisation, Configuration: Release x64 ------
编辑一些东西: 从未找到模块到检测到递归:
(base) C:\Users\---\Documents\SystemConfig\opencv-folder\opencv-master\build\python_loader>python setup.py build
running build
running build_py
(base) C:\Users\---\Documents\SystemConfig\opencv-folder\opencv-master\build\python_loader>python setup.py install
running install
running bdist_egg
running egg_info
writing opencv.egg-info\PKG-INFO
writing dependency_links to opencv.egg-info\dependency_links.txt
writing requirements to opencv.egg-info\requires.txt
writing top-level names to opencv.egg-info\top_level.txt
reading manifest file 'opencv.egg-info\SOURCES.txt'
writing manifest file 'opencv.egg-info\SOURCES.txt'
installing library code to build\bdist.win-amd64\egg
running install_lib
running build_py
creating build\bdist.win-amd64\egg
creating build\bdist.win-amd64\egg\cv2
copying build\lib\cv2\config-2.7.py -> build\bdist.win-amd64\egg\cv2
copying build\lib\cv2\config-3.7.py -> build\bdist.win-amd64\egg\cv2
copying build\lib\cv2\config.py -> build\bdist.win-amd64\egg\cv2
copying build\lib\cv2\load_config_py2.py -> build\bdist.win-amd64\egg\cv2
copying build\lib\cv2\load_config_py3.py -> build\bdist.win-amd64\egg\cv2
copying build\lib\cv2\__init__.py -> build\bdist.win-amd64\egg\cv2
byte-compiling build\bdist.win-amd64\egg\cv2\config-2.7.py to config-2.7.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\cv2\config-3.7.py to config-3.7.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\cv2\config.py to config.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\cv2\load_config_py2.py to load_config_py2.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\cv2\load_config_py3.py to load_config_py3.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\cv2\__init__.py to __init__.cpython-37.pyc
creating build\bdist.win-amd64\egg\EGG-INFO
copying opencv.egg-info\PKG-INFO -> build\bdist.win-amd64\egg\EGG-INFO
copying opencv.egg-info\SOURCES.txt -> build\bdist.win-amd64\egg\EGG-INFO
copying opencv.egg-info\dependency_links.txt -> build\bdist.win-amd64\egg\EGG-INFO
copying opencv.egg-info\requires.txt -> build\bdist.win-amd64\egg\EGG-INFO
copying opencv.egg-info\top_level.txt -> build\bdist.win-amd64\egg\EGG-INFO
zip_safe flag not set; analyzing archive contents...
cv2.__pycache__.__init__.cpython-37: module references __file__
creating 'dist\opencv-4.3.0-py3.7.egg' and adding 'build\bdist.win-amd64\egg' to it
removing 'build\bdist.win-amd64\egg' (and everything under it)
Processing opencv-4.3.0-py3.7.egg
removing 'a:\programdata\anaconda3\lib\site-packages\opencv-4.3.0-py3.7.egg' (and everything under it)
creating a:\programdata\anaconda3\lib\site-packages\opencv-4.3.0-py3.7.egg
Extracting opencv-4.3.0-py3.7.egg to a:\programdata\anaconda3\lib\site-packages
opencv 4.3.0 is already the active version in easy-install.pth
Installed a:\programdata\anaconda3\lib\site-packages\opencv-4.3.0-py3.7.egg
Processing dependencies for opencv==4.3.0
Searching for numpy==1.18.1
Best match: numpy 1.18.1
Adding numpy 1.18.1 to easy-install.pth file
Installing f2py-script.py script to A:\ProgramData\Anaconda3\Scripts
Installing f2py.exe script to A:\ProgramData\Anaconda3\Scripts
Using a:\programdata\anaconda3\lib\site-packages
Finished processing dependencies for opencv==4.3.0
(base) C:\Users\---\Documents\SystemConfig\opencv-folder\opencv-master\build\python_loader>
【问题讨论】: