简体   繁体   English

Opencv 错误:没有 GPU 支持(库在没有 CUDA 支持的情况下编译)

[英]Opencv Error: no GPU support (library is compiled without CUDA support)

I am trying to work some image-process tasks with opencv on GPU with CUDA.我正在尝试使用 CUDA 在 GPU 上使用 opencv 处理一些图像处理任务。 I am using ubuntu.我正在使用 ubuntu。 I setup my two products Opencv and Cuda without a problem, I am sure about that.我毫无问题地设置了我的两个产品 Opencv 和 Cuda,我对此很确定。 However, when I attempt to run sampleCOde in eclipse, I have get an error:但是,当我尝试在 Eclipse 中运行 sampleCOde 时,出现错误:

OpenCV Error: No GPU support (The library is compiled without CUDA support) in mallocPitch, file /home/muad/Source/OpenCV-2.4.2/modules/core/src/gpumat.cpp, line 749

I remade my opencv, but I still get that.我重新制作了我的opencv,但我仍然明白。

As stated in the documentation, you have to build OpenCV using CMake and set the flag WITH_CUDA=ON.如文档中所述,您必须使用 CMake 构建 OpenCV 并设置标志 WITH_CUDA=ON。 Then you will get the full-featured OpenCV GPU module.然后您将获得功能齐全的 OpenCV GPU 模块。 Otherwise the module is still built, but you recieve an exception with CV_GpuNotSupported.否则,该模块仍会构建,但您会收到 CV_GpuNotSupported 的异常。

For further information, read here: http://docs.opencv.org/modules/gpu/doc/introduction.html欲了解更多信息,请阅读此处: http ://docs.opencv.org/modules/gpu/doc/introduction.html

I had the same problem.我有同样的问题。 I fixed it by copying opencv_core243d.dll from E:\opencv\build\gpu\x64\vc10\lib folder to the work directory with the .exe.我通过将 opencv_core243d.dll 从E:\opencv\build\gpu\x64\vc10\lib文件夹复制到带有 .exe 的工作目录来修复它。 Don't know why that should matter but it did.不知道为什么这很重要,但确实如此。

I guess your system path is still set to previous dlls which are not compiled with gpu.我猜你的系统路径仍然设置为以前没有用 gpu 编译的 dll。 You should first change your system path after the rebuilt of opencv.您应该在重建 opencv 后首先更改您的系统路径。

If anyone is facing the same issues when trying to run the notebook on Google Colab.如果有人在尝试在 Google Colab 上运行笔记本时遇到同样的问题。 Then here is how I resolved it.然后这就是我解决它的方法。

I tried out many things and came across this blog : https://towardsdatascience.com/how-to-use-opencv-with-gpu-on-colab-25594379945f我尝试了很多东西,发现了这个博客: https ://towardsdatascience.com/how-to-use-opencv-with-gpu-on-colab-25594379945f

The blog describes how to build, OpenCV with CUDA support and then place the final build file (*.so) into the Colab working directory to be accessed and run OpenCV through it.该博客描述了如何构建具有 CUDA 支持的 OpenCV,然后将最终构建文件 (*.so) 放入 Colab 工作目录以进行访问并通过它运行 OpenCV。

Even though I got all the steps done, the issues were not resolved, because Colab has pre-installed OpenCV, which needs to be removed before you can use the compiled build version.尽管我完成了所有步骤,但问题并没有解决,因为 Colab 已经预先安装了 OpenCV,需要先将其删除,然后才能使用编译后的构建版本。

So here are all the steps I took to get OpenCV running on Google Colab with CUDA support.以下是我在支持 CUDA 的 Google Colab 上运行 OpenCV 所采取的所有步骤。

  1. Enabled the GPU in Colab runtime.在 Colab 运行时启用 GPU。 By selecting 'changing runtime type' in the view resources option and then selecting 'GPU' under the hardware accelerator option.通过在查看资源选项中选择“更改运行时类型”,然后在硬件加速器选项下选择“GPU”。
  2. Mount your google drive into Colab.将您的谷歌驱动器安装到 Colab 中。 This can be easily done by selecting the 'Mount drive' option in the 'Files' tab, allowing your drive to be connected.这可以通过选择“文件”选项卡中的“安装驱动器”选项轻松完成,从而连接您的驱动器。 This Step is important because we need to keep the build file somewhere so as to use it in the future.这一步很重要,因为我们需要将构建文件保存在某个地方以便将来使用它。
  3. Run the below command in the notebook to check the 'cv2' current version在笔记本中运行以下命令以检查“cv2”当前版本
    import cv2
    cv2.__version__
  4. Run the below code in the notebook which will download and build the OpenCV with CUDA support在笔记本中运行以下代码,它将下载并构建具有 CUDA 支持的 OpenCV
    %cd /content
    !git clone https://github.com/opencv/opencv
    !git clone https://github.com/opencv/opencv_contrib
    !mkdir /content/build
    %cd /content/build
    !cmake -DOPENCV_EXTRA_MODULES_PATH=/content/opencv_contrib/modules -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF -DBUILD_EXAMPLES=OFF -DWITH_OPENEXR=OFF -DWITH_CUDA=ON -DWITH_CUBLAS=ON -DWITH_CUDNN=ON -DOPENCV_DNN_CUDA=ON /content/opencv
    !make -j8 install
    This will take a lot of time to run.这将花费大量时间来运行。 It took me 4 hours to complete.我花了4个小时才完成。 Have patience!有耐心!
  5. Once the file is built, we need to copy this build file into our google drive.构建文件后,我们需要将此构建文件复制到我们的谷歌驱动器中。 This can be done using the below command.这可以使用以下命令来完成。 I copied the entire folder, you need not need to do that, just the output file 'build/lib/python3/cv2.cpython-37m-x86_64-linux-gnu.so' is also enough.我复制了整个文件夹,你不需要这样做,只需输出文件'build/lib/python3/cv2.cpython-37m-x86_64-linux-gnu.so'就足够了。
    !mkdir "/content/drive/MyDrive/"
    !cp -R /content/build "/content/drive/MyDrive/"
  6. Now Terminate the session and restart the runtime.现在终止会话并重新启动运行时。 This will clean up all the files and we will have a fresh runtime.这将清理所有文件,我们将有一个新的运行时。
  7. Remount the google drive as same as in step 2.与第 2 步一样重新安装 google 驱动器。
  8. Uninstall the preinstalled OpenCV using below command.使用以下命令卸载预装的 OpenCV。
    !pip uninstall opencv-python
  9. Copy the 'cv2.cpython-37m-x86_64-linux-gnu.so' file into your present working directory将“cv2.cpython-37m-x86_64-linux-gnu.so”文件复制到您当前的工作目录中
    !cp "/content/drive/MyDrive/build/lib/python3/cv2.cpython-37m-x86_64-linux-gnu.so" .
  10. Check the OpenCV version.检查 OpenCV 版本。 It should suffix something like '-pre' or '-dev' in the version number.它应该在版本号中添加类似“-pre”或“-dev”的后缀。 In my case, it was '4.5.5-dev'就我而言,它是“4.5.5-dev”

That's all.就这样。 Make sure to make appropriate changes in the file path if you are using some other location when copying the files from and to the google drive.如果在将文件从 Google 驱动器复制到 google 驱动器时使用其他位置,请确保对文件路径进行适当的更改。

If you think, I missed something or something is incorrect, please let me know.如果您认为我遗漏了某些内容或某些内容不正确,请告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM