Setup OpenCV-DNN module with CUDA backend support on Windows

preview_player
Показать описание
This video shows step by step tutorial on how to set up the OpenCV-DNN module with CUDA backend support on Windows.

① ⚡⚡ Website Blog post on this ⚡⚡

⚡⚡ Medium post ⚡⚡

② ⚡⚡ Website Blog post on CUDA & cuDNN installation ⚡⚡

⚡⚡ Medium post on CUDA & cuDNN installation ⚡⚡

③ ⚡⚡ Required Software ⚡⚡

④ ⚡⚡ CUDA Toolkit download links ⚡⚡

⑤ ⚡⚡ Latest cuDNN version download ⚡⚡
⚡⚡ cuDNN archive download link ⚡⚡

⑥ ⚡⚡ OpenCV download link ⚡⚡

⑦ ⚡⚡ CUDA compiler Compute Capability(CC) link ⚡⚡

#opencvdnncuda #opencvdnn #objectdetection #opencvdnnwindows
▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬

▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
Making these videos takes a lot of time and effort, so if you like these videos and if you can, then please support the channel using any of the following:

► Buy me a coffee! ☕

► Support channel on Patreon! 🖖


▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
Thanks for watching!
Рекомендации по теме
Комментарии
Автор

It would be very interesting if you showed this process with opencvsharp, thanks for the content

losxmsaw
Автор

everything was smooth sailing till 23:18 "C:\Program Files\CMake\bin\cmake.exe" --build "C:\opencv\build" --target INSTALL --config Release I racked up errors

error-
C:\MinGW\include\float.h(57, 1): fatal error C1021: invalid preprocessor command 'include_next' (compiling source file \opencv_world_AVX2.vcxproj]

all the error were this seems that error is due to MinGW not supporting include_next I have to use visual studio build solution please make a video how to do so 🤕😭

swagatrout
Автор

Thank you for the tutorial @techzizou
I have followed all the instructions carefully, but when importing cv2 in the conda environment it fails.

```
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'cv2'
```

Where did I miss? and how to solve this?

alis.albustami
Автор

I have been using OpenCV (installed using "pip") in many of my python programs using base environment. I don't wish to create a virtual environment for now. To have these same programs use my new OpenCV with CUDA, will I need to run "pip uninstall opencv-python" and expect my python programs recognize the existence of the new OpenCV with CUDA version?

ManuelHernandez-zqem
Автор

Thanks a lot for the tutorial!
I have followed your tutorial multiple times, but when running the cmd command in C:\opencv,
there seems to be an error regarding the code in

and in


the error message is as follows:
C:\opencv\opencv-4.7.0\modules\dnn\src\layers\../cuda4dnn/primitives/region.hpp(124, 1): error C2666: 'cv::operator >':
14개 오버로드에 비슷한 변환이 있습니다. (소스 파일 컴파일 중 [C:\opencv\build\m


C:\opencv\opencv-4.7.0\modules\dnn\src\layers\../cuda4dnn/primitives/normalize_bbox.hpp(114, 1): error C2666: 'cv::opera
tor !=': 14개 오버로드에 비슷한 변환이 있습니다. (소스 파일 컴파일 중 [


Seems like operators '>' and '!=' are defined(overloaded) for various templates so it doesn't know which to choose, but i've got no idea how to fix it.

I am using Windows10 and Visual Studio 2019, and trying to build opencv4.7.0 with CUDA12.2 in a virtual environment.
Python version is 3.11.4.

I tried this with various versions of opencv and CUDA.
The cmd command step worked fine with opencv4.5.5 and CUDA11.0, but python failed to import cv2 afterwards.

Any suggestions on how to solve this problem?
I have double-checked all the environment & Cmake variables, and CMake configuration lead to no errors, only some warnings.

동도로동-lv
Автор

In cmake, while building python3 is not displayed???? .

vivekyadav
Автор

CMake Error at modules/dnn/CMakeLists.txt:52 (message):
DNN: CUDA backend requires cuDNN. Please resolve dependency or disable
OPENCV_DNN_CUDA=OFF

-Butterflies-
Автор

I noticed right from the beginning (the first time the configure button from CMake GUI was clicked), the "install" folder never got created inside the "build" folder. I installed CUDA 11.7 and CUDA DNN appropriately. I am installing it in base (no virtual environment). CMake 3.23.1, Python 3.9.13, numpy 1.19.5 and all system variables were set correctly (double checked). The CMake log window did not show any failed nor error messages. And this is the second time I emptied the "build" folder and ran CMake GUI all over again. Is this a bug or rather a recent change? 😕

ManuelHernandez-zqem
Автор

Hello! Do I really have to install Anaconda? I have Puthon 3.9 and PyCharm professional 2022.1 . Can I write the code from Anaconda in Pycharm or in something else? Thank you!

alexaelena
Автор

Hi, first of all thank you for this tutorial :)
I seem to have a problem on the Cmake gui steps. I'm not seeing the "Python3 :" configuration anywhere the BUILD_opencv_python3 option to tick and I dont not see any configuration of Python 3 with interpreter, librairies, numpy and install path after the configuration step. Do you have any idea of what's going on and how can I fix this problem ?

TheAverageOfficial
Автор

Referring to the command that reads:
"C:\Program Files\CMake\bin\cmake.exe" --build "C:\opencv\build" --target INSTALL --config Release

Question: I left the CMAKE_CONFIGURATION_TYPES as is, with "Debug;Release". Should I add "Debug;" before "Release" in the "--config" parameter of the command? In other words, should it read "--config Debug;Release"?

Also, when I typed "CMAKE --help", I could not find the "--config" parameter. Did something change in the most recent version where that parameter no longer exists?

ManuelHernandez-zqem
Автор

Hello I have followed your tutorial and there is no any error but when I run test_DNN_CV.py it shows:

File "C:\Rahma\Speed_bump\test_DNN_CV.py", line 12, in <module>
cuMat1.upload(npMat1)
cv2.error: OpenCV(4.8.0) error: (-216:No CUDA support) The library is compiled without CUDA support in function 'throw_no_cuda'

I use CUDA 11.8, cuDNN 8.9, python 3.9, and cmake 3.27.3

a_rahmawati
Автор

Like always, you are AWESOME! I really appreciate your explanation quality. Thank you.
I have the following five questions:
1) Is there a reason why you choose VS2017 instead of VS2019 or VS2022? And, will it work with VS2022?
2) If I plan on using OpenCV with no virtual environment, do I still need to install Anaconda?
3) If I want to use OpenCV on base and also on a virtual environment, how would I proceed with configuring CMAKE?
4) I suppose the OpenCV with CUDA in the "build" folder can now be used on C++ projects, configuring the "C/C++" and "Linker" project properties in Visual Studio 2022 accordingly? And, it should work with no issues?
5) On CMAKE_CONFIGURATION_TYPES, how can I set both: Debug and Release? I want to see how it performs while debugging a Python and C++ program (in Visual Studio 2022).

I have your email (and have been emailing with you, if you can remember me); however, I thought your answers to my questions above could also be of help to your followers/subscribers. Let me know if you want me to email these questions instead though. Again, thank you! :)

ManuelHernandez-zqem
Автор

I have a problem with CMake. I do everything as in the video but I always get the error: "CMake Error at CMakeLists.txt:113 (enable_language):
Failed to run MSBuild command:
C:/Program Files (x86)/Microsoft Visual
to get the value of VCTargetsPath:"

The MSBuild tool is of course fully installed. I've been looking for a solution everywhere but to no avail. I tried on different versions of Cmake and VS. Do you know what could be wrong?

mariuszlesnik
Автор

This is driving me nuts. The build always stops at this error:

CMake Error at modules/dnn/CMakeLists.txt:35 (message):
DNN: CUDA backend requires CUDA Toolkit. Please resolve dependency or
disable OPENCV_DNN_CUDA=OFF
Call Stack (most recent call first):
(include)
(include_one_module)

I searched everywhere but can't find a solution. It's like it didn't find the CUDA toolkit, but I have set the path and double checked togheter with your video. Do you have any idea how to fix this?

KakashiSharing
Автор

I got error dll not found can any one suggest how to solve i follow the video and done step as per it

: DLL load failed while importing cv2: The specified module could not be found.

aditimahajan-lpxm
Автор

Hello, I'm not seeing an option OPENCV_DNN_CUDA to tick.. what could be the issue.? Please help me

lintotony
Автор

Hi thank you for the video, it is a great tutorial, i have done everything exactly like in the video and didin't get any error until when i try to import cv2 from the command prompt
I get this error;
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.

Can you help me with this. I am working on an object detection project and i need to run the python code with my gpu. Thank you for your help.

waef
Автор

Hello, I got a couple of few issues here:

1) Right after I ran ["C:\Program Files\CMake\bin\cmake.exe" --build "C:\opencv\build" --target INSTALL --config Release], the "...build\install" folder never got created after several attempts, like it does in your video.

2) So I opened the "...build\OpenCV.sln" in VS2022, expanded "CMakeTargets", right-clicked "INSTALL" and selected "Build" and had many failed errors that read [LINK : fatal error LNK1181: cannot open input file This file in fact never got created.

3) I emptied the "build" folder, ran CMake GUI all over again from scratch and instead of running the CMake command, I opened the "...build\OpenCV.sln" in VS2022, expanded "CMakeTargets", right-clicked "ALL_BUILD" and selected "Build" and had many failed errors that read [LINK : fatal error LNK1181: cannot open input file This file in fact never got created.

Any clues on how to prevent or fix this issue(s)? I will appreciate :)

OS: Windows 11
MS Visual Studio: 2022 (also tried 2019)
Python: 3.9.13
numpy: 1.19.5
CMake: 3.23.2
CUDA (nvcc --version): 11.7.64
OpenCV: 4.60 (also tried 4.5.5)
OpenCV_Contrib: 4.60 (also tried 4.5.5)

ManuelHernandez-zqem
Автор

I always get this error :
D:\OpenCVGPU\opencv-4.x\modules\core\include\opencv2/core/cuda/common.hpp(101, 27): so on (There are so many error related to common.hpp)
Does anybody know how to fix this? (I am using Windows 11)

da_