Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

c

opencv

cuda

I am trying to work some image-process tasks with opencv on GPU with CUDA. I am using ubuntu. I setup my two products Opencv and Cuda without a problem, I am sure about that. However, when I attempt to run sampleCOde in eclipse, I have get an error:

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.

like image 949
Bce Avatar asked Oct 16 '12 08:10

Bce


4 Answers

As stated in the documentation, you have to build OpenCV using CMake and set the flag WITH_CUDA=ON. Then you will get the full-featured OpenCV GPU module. Otherwise the module is still built, but you recieve an exception with CV_GpuNotSupported.

For further information, read here: http://docs.opencv.org/modules/gpu/doc/introduction.html

like image 133
Maecky Avatar answered Nov 15 '22 14:11

Maecky


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. Don't know why that should matter but it did.

like image 22
john ktejik Avatar answered Nov 15 '22 14:11

john ktejik


I guess your system path is still set to previous dlls which are not compiled with gpu. You should first change your system path after the rebuilt of opencv.

like image 1
ytdonkey Avatar answered Nov 15 '22 15:11

ytdonkey


If anyone is facing the same issues when trying to run the notebook on 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

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.

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.

So here are all the steps I took to get OpenCV running on Google Colab with CUDA support.

  1. Enabled the GPU in Colab runtime. By selecting 'changing runtime type' in the view resources option and then selecting 'GPU' under the hardware accelerator option.
  2. Mount your google drive into 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
    import cv2
    cv2.__version__
  4. Run the below code in the notebook which will download and build the OpenCV with CUDA support
    %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. 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.
    !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.
  8. Uninstall the preinstalled OpenCV using below command.
    !pip uninstall opencv-python
  9. Copy the 'cv2.cpython-37m-x86_64-linux-gnu.so' file into your present working directory
    !cp "/content/drive/MyDrive/build/lib/python3/cv2.cpython-37m-x86_64-linux-gnu.so" .
  10. Check the OpenCV version. It should suffix something like '-pre' or '-dev' in the version number. In my case, it was '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.

If you think, I missed something or something is incorrect, please let me know.

like image 1
SWAPNIL SABLE Avatar answered Nov 15 '22 16:11

SWAPNIL SABLE