'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. 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.
Solution 1:[1]
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.
Solution 2:[2]
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.
Solution 3:[3]
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.
- 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.
- 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.
- Run the below command in the notebook to check the 'cv2' current version
?import cv2
?cv2.__version__ - 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! - 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/" - Now Terminate the session and restart the runtime. This will clean up all the files and we will have a fresh runtime.
- Remount the google drive as same as in step 2.
- Uninstall the preinstalled OpenCV using below command.
?!pip uninstall opencv-python - 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" . - 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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | john ktejik |
| Solution 2 | ytdonkey |
| Solution 3 | SWAPNIL SABLE |
