Build OpenCV from source with CUDA support

该博客介绍了如何构建带有CUDA支持的OpenCV,以及如何利用多个GPU。OpenCV的GPU模块使用NVIDIA CUDA Runtime API,支持NVIDIA GPU,提供从低级到高级的视觉算法。通过CMake配置WITH_CUDA=ON可启用CUDA支持。对于不同NVIDIA平台,OpenCV默认包含1.3和2.0计算能力的二进制文件及1.1和1.3的PTX代码。要利用多GPU,需要手动分配工作,并使用gpu::setDevice()切换设备。对于高阶算法,如立体匹配,多GPU加速可以显著提高性能。
部署运行你感兴趣的模型镜像


GPU Module Introduction


 General Information

The OpenCV GPU module is a set of classes and functions to utilize GPU computational capabilities. It is implemented using NVIDIA* CUDA* Runtime API and supports only NVIDIA GPUs. The OpenCV GPU module includes utility functions, low-level vision primitives, and high-level algorithms. The utility functions and low-level primitives provide a powerful infrastructure for developing fast vision algorithms taking advantage of GPU whereas the high-level functionality includes some state-of-the-art algorithms (such as stereo correspondence, face and people detectors, and others) ready to be used by the application developers.

The GPU module is designed as a host-level API. This means that if you have pre-compiled OpenCV GPU binaries, you are not required to have the CUDA Toolkit installed or write any extra code to make use of the GPU.

The OpenCV GPU module is designed for ease of use and does not require any knowledge of CUDA. Though, such a knowledge will certainly be useful to handle non-trivial cases or achieve the highest performance. It is helpful to understand the cost of various operations, what the GPU does, what the preferred data formats are, and so on. The GPU module is an effective instrument for quick implementation of GPU-accelerated computer vision algorithms. However, if your algorithm involves many simple operations, then, for the best possible performance, you may still need to write your own kernels to avoid extra write and read operations on the intermediate results.

To enable CUDA support, configure OpenCV using CMake with WITH_CUDA=ON . When the flag is set and if CUDA is installed, the full-featured OpenCV GPU module is built. Otherwise, the module is still built but at runtime all functions from the module throwException with CV_GpuNotSupported error code, except for gpu::getCudaEnabledDeviceCount(). The latter function returns zero GPU count in this case. Building OpenCV without CUDA support does not perform device code compilation, so it does not require the CUDA Toolkit installed. Therefore, using the gpu::getCudaEnabledDeviceCount() function, you can implement a high-level algorithm that will detect GPU presence at runtime and choose an appropriate implementation (CPU or GPU) accordingly.

 Compilation for Different NVIDIA* Platforms

NVIDIA* compiler enables generating binary code (cubin and fatbin) and intermediate code (PTX). Binary code often implies a specific GPU architecture and generation, so the compatibility with other GPUs is not guaranteed. PTX is targeted for a virtual platform that is defined entirely by the set of capabilities or features. Depending on the selected virtual platform, some of the instructions are emulated or disabled, even if the real hardware supports all the features.

At the first call, the PTX code is compiled to binary code for the particular GPU using a JIT compiler. When the target GPU has a compute capability (CC) lower than the PTX code, JIT fails. By default, the OpenCV GPU module includes:

  • Binaries for compute capabilities 1.3 and 2.0 (controlled by CUDA_ARCH_BIN in CMake)
  • PTX code for compute capabilities 1.1 and 1.3 (controlled by CUDA_ARCH_PTX in CMake)

This means that for devices with CC 1.3 and 2.0 binary images are ready to run. For all newer platforms, the PTX code for 1.3 is JIT’ed to a binary image. For devices with CC 1.1 and 1.2, the PTX for 1.1 is JIT’ed. For devices with CC 1.0, no code is available and the functions throw Exception. For platforms where JIT compilation is performed first, the run is slow.

On a GPU with CC 1.0, you can still compile the GPU module and most of the functions will run flawlessly. To achieve this, add “1.0” to the list of binaries, for example, CUDA_ARCH_BIN="1.0 1.3 2.0" . The functions that cannot be run on CC 1.0 GPUs throw an exception.

You can always determine at runtime whether the OpenCV GPU-built binaries (or PTX code) are compatible with your GPU. The function gpu::DeviceInfo::isCompatible() returns the compatibility status (true/false).

 Utilizing Multiple GPUs

In the current version, each of the OpenCV GPU algorithms can use only a single GPU. So, to utilize multiple GPUs, you have to manually distribute the work between GPUs. Switching active devie can be done using gpu::setDevice() function. For more details please read Cuda C Programming Guide.

While developing algorithms for multiple GPUs, note a data passing overhead. For primitive functions and small images, it can be significant, which may eliminate all the advantages of having multiple GPUs. But for high-level algorithms, consider using multi-GPU acceleration. For example, the Stereo Block Matching algorithm has been successfully parallelized using the following algorithm:

  1. Split each image of the stereo pair into two horizontal overlapping stripes.
  2. Process each pair of stripes (from the left and right images) on a separate Fermi* GPU.
  3. Merge the results into a single disparity map.

With this algorithm, a dual GPU gave a 180 % performance increase comparing to the single Fermi GPU. For a source code example, see https://github.com/Itseez/opencv/tree/master/samples/gpu/.



链接:http://docs.opencv.org/modules/gpu/doc/introduction.html




您可能感兴趣的与本文相关的镜像

PyTorch 2.5

PyTorch 2.5

PyTorch
Cuda

PyTorch 是一个开源的 Python 机器学习库,基于 Torch 库,底层由 C++ 实现,应用于人工智能领域,如计算机视觉和自然语言处理

严重性 代码 说明 项目 文件 行 抑制状态 详细信息 错误 MSB8066 “E:\workspace\source\OpenCV\opencv_build\opencv-4.8.0\modules\core\src\cuda\gpu_mat.cu;E:\workspace\source\OpenCV\opencv_build\opencv-4.8.0\modules\core\src\cuda\gpu_mat_nd.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudaarithm\src\cuda\absdiff_mat.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudaarithm\src\cuda\absdiff_scalar.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudaarithm\src\cuda\add_mat.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudaarithm\src\cuda\add_scalar.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudaarithm\src\cuda\add_weighted.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudaarithm\src\cuda\bitwise_mat.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudaarithm\src\cuda\bitwise_scalar.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudaarithm\src\cuda\cmp_mat.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudaarithm\src\cuda\cmp_scalar.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudaarithm\src\cuda\copy_make_border.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudaarithm\src\cuda\countnonzero.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudaarithm\src\cuda\div_mat.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudaarithm\src\cuda\div_scalar.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudaarithm\src\cuda\in_range.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudaarithm\src\cuda\integral.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudaarithm\src\cuda\lut.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudaarithm\src\cuda\math.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudaarithm\src\cuda\minmax.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudaarithm\src\cuda\minmax_mat.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudaarithm\src\cuda\minmaxloc.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudaarithm\src\cuda\mul_mat.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudaarithm\src\cuda\mul_scalar.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudaarithm\src\cuda\mul_spectrums.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudaarithm\src\cuda\norm.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudaarithm\src\cuda\normalize.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudaarithm\src\cuda\polar_cart.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudaarithm\src\cuda\reduce.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudaarithm\src\cuda\split_merge.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudaarithm\src\cuda\sub_mat.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudaarithm\src\cuda\sub_scalar.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudaarithm\src\cuda\sum.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudaarithm\src\cuda\threshold.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudaarithm\src\cuda\transpose.cu;E:\workspace\source\OpenCV\opencv_build\build4.8.0\CMakeFiles\9dc87ef146f8f62aff4a37b51462d390\opencl_kernels_imgproc.cpp.rule;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudafilters\src\cuda\column_filter.16sc1.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudafilters\src\cuda\column_filter.16sc3.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudafilters\src\cuda\column_filter.16sc4.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudafilters\src\cuda\column_filter.16uc1.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudafilters\src\cuda\column_filter.16uc3.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudafilters\src\cuda\column_filter.16uc4.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudafilters\src\cuda\column_filter.32fc1.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudafilters\src\cuda\column_filter.32fc3.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudafilters\src\cuda\column_filter.32fc4.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudafilters\src\cuda\column_filter.32sc1.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudafilters\src\cuda\column_filter.32sc3.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudafilters\src\cuda\column_filter.32sc4.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudafilters\src\cuda\column_filter.8uc1.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudafilters\src\cuda\column_filter.8uc3.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudafilters\src\cuda\column_filter.8uc4.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudafilters\src\cuda\filter2d.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudafilters\src\cuda\median_filter.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudafilters\src\cuda\row_filter.16sc1.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudafilters\src\cuda\row_filter.16sc3.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudafilters\src\cuda\row_filter.16sc4.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudafilters\src\cuda\row_filter.16uc1.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudafilters\src\cuda\row_filter.16uc3.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudafilters\src\cuda\row_filter.16uc4.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudafilters\src\cuda\row_filter.32fc1.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudafilters\src\cuda\row_filter.32fc3.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudafilters\src\cuda\row_filter.32fc4.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudafilters\src\cuda\row_filter.32sc1.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudafilters\src\cuda\row_filter.32sc3.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudafilters\src\cuda\row_filter.32sc4.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudafilters\src\cuda\row_filter.8uc1.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudafilters\src\cuda\row_filter.8uc3.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudafilters\src\cuda\row_filter.8uc4.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudaimgproc\src\cuda\bilateral_filter.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudaimgproc\src\cuda\blend.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudaimgproc\src\cuda\build_point_list.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudaimgproc\src\cuda\canny.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudaimgproc\src\cuda\clahe.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudaimgproc\src\cuda\color.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudaimgproc\src\cuda\connectedcomponents.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudaimgproc\src\cuda\corners.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudaimgproc\src\cuda\debayer.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudaimgproc\src\cuda\generalized_hough.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudaimgproc\src\cuda\gftt.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudaimgproc\src\cuda\hist.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudaimgproc\src\cuda\hough_circles.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudaimgproc\src\cuda\hough_lines.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudaimgproc\src\cuda\hough_segments.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudaimgproc\src\cuda\match_template.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudaimgproc\src\cuda\mean_shift.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudawarping\src\cuda\pyr_down.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudawarping\src\cuda\pyr_up.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudawarping\src\cuda\remap.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudawarping\src\cuda\resize.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudawarping\src\cuda\warp.cu;E:\workspace\source\OpenCV\opencv_build\opencv-4.8.0\modules\dnn\src\cuda\activation_eltwise.cu;E:\workspace\source\OpenCV\opencv_build\opencv-4.8.0\modules\dnn\src\cuda\activations.cu;E:\workspace\source\OpenCV\opencv_build\opencv-4.8.0\modules\dnn\src\cuda\bias_activation.cu;E:\workspace\source\OpenCV\opencv_build\opencv-4.8.0\modules\dnn\src\cuda\bias_activation_eltwise.cu;E:\workspace\source\OpenCV\opencv_build\opencv-4.8.0\modules\dnn\src\cuda\bias_eltwise_activation.cu;E:\workspace\source\OpenCV\opencv_build\opencv-4.8.0\modules\dnn\src\cuda\concat.cu;E:\workspace\source\OpenCV\opencv_build\opencv-4.8.0\modules\dnn\src\cuda\crop_and_resize.cu;E:\workspace\source\OpenCV\opencv_build\opencv-4.8.0\modules\dnn\src\cuda\detection_output.cu;E:\workspace\source\OpenCV\opencv_build\opencv-4.8.0\modules\dnn\src\cuda\eltwise_activation.cu;E:\workspace\source\OpenCV\opencv_build\opencv-4.8.0\modules\dnn\src\cuda\eltwise_ops.cu;E:\workspace\source\OpenCV\opencv_build\opencv-4.8.0\modules\dnn\src\cuda\fill_copy.cu;E:\workspace\source\OpenCV\opencv_build\opencv-4.8.0\modules\dnn\src\cuda\fp_conversion.cu;E:\workspace\source\OpenCV\opencv_build\opencv-4.8.0\modules\dnn\src\cuda\grid_nms.cu;E:\workspace\source\OpenCV\opencv_build\opencv-4.8.0\modules\dnn\src\cuda\max_unpooling.cu;E:\workspace\source\OpenCV\opencv_build\opencv-4.8.0\modules\dnn\src\cuda\mvn.cu;E:\workspace\source\OpenCV\opencv_build\opencv-4.8.0\modules\dnn\src\cuda\normalize.cu;E:\workspace\source\OpenCV\opencv_build\opencv-4.8.0\modules\dnn\src\cuda\padding.cu;E:\workspace\source\OpenCV\opencv_build\opencv-4.8.0\modules\dnn\src\cuda\permute.cu;E:\workspace\source\OpenCV\opencv_build\opencv-4.8.0\modules\dnn\src\cuda\prior_box.cu;E:\workspace\source\OpenCV\opencv_build\opencv-4.8.0\modules\dnn\src\cuda\region.cu;E:\workspace\source\OpenCV\opencv_build\opencv-4.8.0\modules\dnn\src\cuda\resize.cu;E:\workspace\source\OpenCV\opencv_build\opencv-4.8.0\modules\dnn\src\cuda\roi_pooling.cu;E:\workspace\source\OpenCV\opencv_build\opencv-4.8.0\modules\dnn\src\cuda\scale_shift.cu;E:\workspace\source\OpenCV\opencv_build\opencv-4.8.0\modules\dnn\src\cuda\shortcut.cu;E:\workspace\source\OpenCV\opencv_build\opencv-4.8.0\modules\dnn\src\cuda\slice.cu;E:\workspace\source\OpenCV\opencv_build\build4.8.0\CMakeFiles\9dc87ef146f8f62aff4a37b51462d390\opencl_kernels_features2d.cpp.rule;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\hfs\src\cuda\gslic_seg_engine_gpu.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\hfs\src\cuda\magnitude.cu;E:\workspace\source\OpenCV\opencv_build\build4.8.0\CMakeFiles\9dc87ef146f8f62aff4a37b51462d390\opencl_kernels_photo.cpp.rule;E:\workspace\source\OpenCV\opencv_build\opencv-4.8.0\modules\photo\src\cuda\nlm.cu;E:\workspace\source\OpenCV\opencv_build\build4.8.0\CMakeFiles\9dc87ef146f8f62aff4a37b51462d390\opencl_kernels_calib3d.cpp.rule;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudacodec\src\cuda\nv12_to_rgb.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudacodec\src\cuda\rgb_to_yv12.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudafeatures2d\src\cuda\bf_knnmatch.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudafeatures2d\src\cuda\bf_match.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudafeatures2d\src\cuda\bf_radius_match.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudafeatures2d\src\cuda\fast.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudafeatures2d\src\cuda\orb.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudastereo\src\cuda\disparity_bilateral_filter.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudastereo\src\cuda\stereobm.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudastereo\src\cuda\stereobp.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudastereo\src\cuda\stereocsbp.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudastereo\src\cuda\stereosgm.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudastereo\src\cuda\util.cu;E:\workspace\source\OpenCV\opencv_build\build4.8.0\CMakeFiles\9dc87ef146f8f62aff4a37b51462d390\opencl_kernels_objdetect.cpp.rule;E:\workspace\source\OpenCV\opencv_build\build4.8.0\CMakeFiles\9dc87ef146f8f62aff4a37b51462d390\opencl_kernels_rgbd.cpp.rule;E:\workspace\source\OpenCV\opencv_build\build4.8.0\CMakeFiles\9dc87ef146f8f62aff4a37b51462d390\opencl_kernels_video.cpp.rule;E:\workspace\source\OpenCV\opencv_build\build4.8.0\CMakeFiles\9dc87ef146f8f62aff4a37b51462d390\opencl_kernels_xfeatures2d.cpp.rule;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\xfeatures2d\src\cuda\surf.cu;E:\workspace\source\OpenCV\opencv_build\build4.8.0\CMakeFiles\9dc87ef146f8f62aff4a37b51462d390\opencl_kernels_ximgproc.cpp.rule;E:\workspace\source\OpenCV\opencv_build\build4.8.0\CMakeFiles\9dc87ef146f8f62aff4a37b51462d390\opencl_kernels_bioinspired.cpp.rule;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudabgsegm\src\cuda\mog.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudabgsegm\src\cuda\mog2.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudalegacy\src\cuda\NCV.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudalegacy\src\cuda\NCVBroxOpticalFlow.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudalegacy\src\cuda\NCVHaarObjectDetection.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudalegacy\src\cuda\NCVPyramid.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudalegacy\src\cuda\NPP_staging.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudalegacy\src\cuda\bm.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudalegacy\src\cuda\bm_fast.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudalegacy\src\cuda\calib3d.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudalegacy\src\cuda\ccomponetns.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudalegacy\src\cuda\fgd.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudalegacy\src\cuda\gmg.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudalegacy\src\cuda\needle_map.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudaobjdetect\src\cuda\hog.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudaobjdetect\src\cuda\lbp.cu;E:\workspace\source\OpenCV\opencv_build\build4.8.0\CMakeFiles\9dc87ef146f8f62aff4a37b51462d390\opencl_kernels_optflow.cpp.rule;E:\workspace\source\OpenCV\opencv_build\build4.8.0\CMakeFiles\9dc87ef146f8f62aff4a37b51462d390\opencl_kernels_stitching.cpp.rule;E:\workspace\source\OpenCV\opencv_build\opencv-4.8.0\modules\stitching\src\cuda\build_warp_maps.cu;E:\workspace\source\OpenCV\opencv_build\opencv-4.8.0\modules\stitching\src\cuda\multiband_blend.cu;E:\workspace\source\OpenCV\opencv_build\build4.8.0\CMakeFiles\9dc87ef146f8f62aff4a37b51462d390\opencl_kernels_tracking.cpp.rule;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudaoptflow\src\cuda\farneback.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudaoptflow\src\cuda\nvidiaOpticalFlow.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudaoptflow\src\cuda\pyrlk.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\cudaoptflow\src\cuda\tvl1flow.cu;E:\workspace\source\OpenCV\opencv_build\build4.8.0\CMakeFiles\9dc87ef146f8f62aff4a37b51462d390\opencl_kernels_superres.cpp.rule;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\superres\src\cuda\btv_l1_gpu.cu;E:\workspace\source\OpenCV\opencv_build\opencv_contrib-4.8.0\modules\videostab\src\cuda\global_motion.cu”的自定义生成已退出,代码为 1。 opencv_world E:\workspace\soft\VS\2022\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets 254
06-23
### OpenCV 4.8.0 CUDA Modules 编译错误 MSB8066 的解决方案 在 Windows 环境下使用 Visual Studio 编译 OpenCV 4.8.0 并启用 CUDA 加速时,可能会遇到编译错误 MSB8066。此错误通常与项目配置或依赖项设置不正确有关[^1]。以下是可能的原因及解决方案: #### 1. **检查 CMake 配置** 确保在 CMake 中正确启用了 CUDA 支持,并设置了正确的路径: - `WITH_CUDA` 应设为 `ON`。 - 检查 `CUDA_TOOLKIT_ROOT_DIR` 是否指向正确的 CUDA 安装路径。 - 如果使用了 `opencv_contrib` 模块,确保其路径也正确设置。 如果 CMake 配置不正确,可能会导致编译器无法找到 CUDA 相关的库或头文件,从而引发 MSB8066 错误[^4]。 #### 2. **Visual Studio 和 CUDA 版本兼容性** MSB8066 错误也可能与 Visual Studio 和 CUDA 的版本不匹配有关。根据引用内容[^4],CUDA 12.1 及以上版本支持 Visual Studio 2022,而较旧版本(如 VS 2015)仅支持 CUDA 9.0。请确认以下几点: - 使用的 Visual Studio 版本是否支持所安装的 CUDA 版本。 - 如果版本不匹配,建议升级 Visual Studio 或降级 CUDA 到兼容版本。 #### 3. **编译选项和生成器** 在 CMake 中选择适当的生成器(Generator),例如 `Visual Studio 17 2022`,并确保选择了正确的平台(如 `x64`)。如果生成器选择不当,可能会导致生成的项目文件无法正确解析依赖关系,进而引发 MSB8066 错误[^2]。 #### 4. **清理和重新生成项目** 有时,编译缓存可能导致错误。尝试以下步骤: - 删除之前生成的构建目录。 - 在 CMake 中重新配置并生成新的项目文件。 - 使用 Visual Studio 打开新生成的解决方案并重新编译。 #### 5. **检查环境变量** 确保系统环境变量中正确配置了 CUDA 路径。例如,添加以下路径到 `PATH`: ```plaintext C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.2\bin ``` 此外,确认 `CUDA_PATH` 环境变量指向正确的 CUDA 安装目录[^4]。 #### 6. **依赖项问题** 某些依赖项(如 `ippicv` 或 `face_landmark_model`)可能未正确下载或配置。如果 CMake 提示这些依赖项缺失,请手动下载并放置到指定目录。例如,`ippicv` 的下载链接通常会在 CMake 输出中提供[^4]。 #### 示例代码:CMakeLists.txt 配置片段 以下是 CMakeLists.txt 的部分配置示例,确保启用了 CUDA 支持: ```cmake set(WITH_CUDA ON CACHE BOOL "Enable CUDA support") set(CUDA_TOOLKIT_ROOT_DIR "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.2" CACHE PATH "Path to CUDA toolkit") set(OPENCV_EXTRA_MODULES_PATH "path/to/opencv_contrib/modules" CACHE PATH "Path to opencv_contrib modules") ``` ### 总结 MSB8066 错误通常是由于项目配置、依赖项或工具链版本不匹配引起的。通过检查 CMake 配置、确保工具链兼容性、清理缓存以及手动处理依赖项,可以有效解决此类问题[^1][^2][^4]。 ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值