Quick and Easy OpenCV Python Installation with Cuda GPU in Under 10 Minutes
Вставка
- Опубліковано 20 сер 2024
- Inside my school and program, I teach you my system to become an AI engineer or freelancer. Life-time access, personal help by me and I will show you exactly how I went from below average student to making $250/hr. Join the High Earner AI Career Program here 👉 www.nicolai-ni... (PRICES WILL INCREASE SOON)
You will also get access to all the technical courses inside the program, also the ones I plan to make in the future! Check out the technical courses below 👇
_____________________________________________________________
In this video 📝 I teach you my system to become an AI engineer or freelancer. Life-time access, personal help by me and I will show you exactly how I went from below average student to making $250/hr. Join the High Earner AI Career Program here 👉 www.nicolai-ni... (PRICES WILL INCREASE SOON)
You will also get access to all the technical courses inside the program, also the ones I plan to make in the future! Check out the technical courses below 👇
If you enjoyed this video, be sure to press the 👍 button so that I know what content you guys like to see.
_____________________________________________________________
🛠️ Freelance Work: www.nicolai-ni...
_____________________________________________________________
💻💰🛠️ High Earner AI Career Program: www.nicolai-ni...
⚙️ Real-world AI Technical Courses: (www.nicos-scho...)
📗 OpenCV GPU in Python: www.nicos-scho...
📕 YOLOv7 Object Detection: www.nicos-scho...
📒 Transformer & Segmentation: www.nicos-scho...
📙 YOLOv8 Object Tracking: www.nicos-scho...
📘 Research Paper Implementation: www.nicos-scho...
📔 CustomGPT: www.nicos-scho...
_____________________________________________________________
📞 Connect with Me:
🌳 linktr.ee/nico...
🌍 My Website: www.nicolai-ni...
🤖 GitHub: github.com/nic...
👉 LinkedIn: / nicolaiai
🐦 X/Twitter: / nielsencv_ai
🌆 Instagram: / nicolaihoeirup
_____________________________________________________________
🎮 My Gear (Affiliate links):
💻 Laptop: amzn.to/49LJkTW
🖥️ Desktop PC:
NVIDIA RTX 4090 24GB: amzn.to/3Uc7yAM
Intel I9-14900K: amzn.to/3W4Z5Cb
Motherboard: amzn.to/4aR6wBC
32GB RAM: amzn.to/3Jt2XVR
🖥️ Monitor: amzn.to/4aLP8hh
🖱️ Mouse: amzn.to/3W501GH
⌨️ Keyboard: amzn.to/3xUGz5b
🎙️ Microphone: amzn.to/3w1F1WK
📷 Camera: amzn.to/4b4Ryr9
_____________________________________________________________
Tags:
#OpenCV #opencvGPU #NVIDIA #Cuda #ComputerVision #OpenCVpython #Python
Join My AI Career Program
www.nicolai-nielsen.com/aicareer
Enroll in My School and Technical Courses
www.nicos-school.com
Thank you Nicolai, Two Days I can't sleep resolving this!
Awesome man! Hope you can get some sleep now
I am using VS 2022 Professional and this works fine no issues thanks bro !
Thanks! Glad that it worked out
I am using V4.70 the latest it all seems to work fine there is no issues I did try the version in the video and it came up with lots of RED errors @@NicolaiAI
Awesome tutorial. One question though, how can i use the cv2 package in other virtual environments? I tried creating a sym link from the virtual env site packages folder to the base anaconda cv2 package but importing fails
I tried many times but there is an error showing up
error C4430: missing ty
pe specifier - int assumed. Note: C++ does not support default-int (compiling source file C:\Users\ankit\OpencvGpu\buil
d\modules\world\mathfuncs_core.avx.cpp) [C:\Users\ankit\OpencvGpu\build\modules\world\opencv_world_AVX.vcxproj]
Nice tutorial mate, I had a lot of issues but following everything step by step IT WORKED. I used regular python (not Anaconda) :)
Thanks for watching! Glad that it helped u out
@@NicolaiAI Hi, I'm getting this error when trying to import the generated cv2 library to python: ImportError: DLL load failed while importing cv2: The specified module could not be found. Any thoughts?
Hello, I wanted to use regular python also with vs code, but when I try to import it in the terminal with python, the following error appears: "ModuleNotFoundError No module named cv2"
Can you help me?
@@Anndres47 I had the same issue. I tried to debug it with looking at the dependencies of the pyd file. I didn't find anything missing but some windows libraries are imported in a way that they end up running down a recursive include. I think the python import times out or has a limited depth for the dependencies. (1 get a 7k dll dependencies with a depth of 10)
I didn't need to rebuild I just needed to install anaconda and add: os.add_dll_directory(r'C:\Users\username\Anaconda3\Library\bin') to the init of the package.
@@filipecarvalho5812 Did you run the install after the build? You need to have the package either in your user python directory or in the system wide.
In the default configuration it tries to install in the system python which needs admin rights.
As commented in my other comment you will need to install anaconda anyway. So you can also go straight for that.
I did what you said excitely with CUDA11.3,CMAKE2.4.2,OPENCV4.5.2(and contrib) but when i want to try the last thing of import cv2 example i gave that error and i think it couldn't installed correctly.
I tried almost 20 hours it but i couldn't success.
what can i do please help me.
*******************
>>> import cv2
Traceback (most recent call last):
File "", line 1, in
ModuleNotFoundError: No module named 'cv2'
******************
Hello, did you manage to solve the error? I tried to install it three times and i get the same output. I Would really appreciate some help. Thanks
@@tudoreugenchindea2414hi bro, I also encountered the same problem.Did you fix it?😢.Thanks bro🙏🏻🙏🏻
" The library is compiled without CUDA support in function 'throw_no_cuda' "
somebody face this issue?
opencv : 4.6
python : 3.9.13
cuda version : 11.7
I from Brazil Tanks brow
Thanks a lot for watching bro!
I waited for it to build for 2 hours and at the end it failed because i didnt run cmd in administrator mode...
If u rerun with admin it will take a few mins
6:20 I didn't understand how to choose the correct bin number. Why did you let 6.1:8.6? Is it the range of your GPU's transistors?
It’s the version of ur gpu. Can be found on wiki as showed in the video
Hello, I have been googling and I have not found anything regarding feature extraction (ORB, SIFT, SURF) for CUDA in python, where could I find some information, everything that appears is in C++, could someone help me?
I’ll make a tutorial about OpenCV gpu with python
@@NicolaiAI Ohh great thanks because I can't find anything about feature extraction, visual odometry in python using CUDA
Sameeeeee question here
its saying that
Traceback (most recent call last):
File "", line 1, in
ModuleNotFoundError: No module named 'cv2'
Hello, did you manage to solve the error? I tried to install it three times and i get the same output. I Would really appreciate some help. Thanks
I got the same issue as well. Struggling this for few days.
Please help me fixing this error: CMake Error at modules/dnn/CMakeLists.txt:41 (message):
DNN: CUDA backend requires cuDNN. Please resolve dependency or disable
OPENCV_DNN_CUDA=OFF
disable cudnn from the cmake config
Thank you very much for the thorough walkthrough! Everything seems to be going well for me except for the final part. I tried with VS 16 2019, and VS 17 2022, and still getting the exact same error every time. I even tried changing the directories:
cuda.printCudaDeviceInfo(0)
Traceback (most recent call last):
File "", line 1, in
cv2.error: OpenCV(4.8.0) D:\a\opencv-python\opencv-python\opencv\modules\core\include\opencv2/core/private.cuda.hpp:106: error: (-216:No CUDA support) The library is compiled without CUDA support in function 'throw_no_cuda'.
I'm running on RTX 3050, so my CUDA_ARCH_BIN is 8.6. Please let me know how to resolve this. Thank you again!
EDIT: I forgot to mention. I have CUDA 12.2. I don't know if that affects things or not.
Opencv version is 4.5.2 not a 4.8.0
@antonioentringer5947 This reply is wrong on many levels. One of the obvious ones is to imply that this only works for version 4.5.2, not 4.8.0 (which is not at all true if you read other sites, or just the comment section, really). Second, it doesn't address at all the error in question, nor the description provided for it. OpenCV IS being detected. Even in other versions, it would get detected, but still, it would give the same error.
@@afollowerofchrist5789 did you ever figure this out? I'm having the same issue
@@Seedx Yes, actually, but surprisingly, it worked on Visual Studio 2019 instead of Jupyter Notebook, even though that's where I had installed everything. OK, so just delete the "build" folder, and restart everything from scratch just like in the video. HOWEVER, there is a key difference here. You see, there is actually a developer fault in both files "region.hpp" and "normalize_bbox.hpp". These files are found in: ...opencv-4.8.0\modules\dnn\src\cuda4dnn\primitives.
I won't go into the details, but what you have to do is fix the following lines in the command:
In region.hpp:
Replace:
*if (nms_iou_threshold > 0.0)*
With:
*if (nms_iou_threshold > static_cast(0.0))*
And in normalize_bbox.hpp:
Replace:
*if (weight != 1.0)*
With:
*if (weight != static_cast(1.0))*
Now, rebuild everything just like in the video. Run your code in Visual Studio environment instead of Jupyter, and it will work. It did for me.
LINK : fatal error LNK1181: cannot open input file 'lib.lib' [C:\Users\admin\opencvGPU\build\modules\world\opencv_world
.vcxproj]
Im getting this error after running the command line .
thanks for the video! I did it. how do I create a python package from this build that can simply be installed on another computer?
Thanks for watching! My pleasure. You can use docket for that and just include the cmake installation in the dockerfile. You would need to specify the arguments in cmake instead of the gui. Might do a video about it soon!
ive literally struggled an week with this and still cannot get it to work
"module 'cv2' has no attribute 'dnn'"
U have to check that off in cmake as well
cudnn is always showing no after I do everything as directed please help I am struggling a lot
Thanks for tutorial! I faced the issue that it works in cmd, but in pycharm venv it outputs cv2.error: OpenCV(4.8.0) D:\a\opencv-python\opencv-python\opencv\modules\core\include\opencv2/core/private.cuda.hpp:106: error: (-216:No CUDA support) The library is compiled without CUDA support in function 'throw_no_cuda'. Has anyone faced it too and fixed?
llegue a lo mismo
I am facing it but still couldn't find a solution
I created a new environment and followed the same steps as you did and everything seemed fine ,until I went to check if it successfully was installed.I got an error when importing cv2 not found. have you any suggestions why ??
CMake Error at modules/dnn/CMakeLists.txt:53 (message):
DNN: CUDA backend requires cuDNN. Please resolve dependency or disable
OPENCV_DNN_CUDA=OFF
Call Stack (most recent call first):
modules/world/CMakeLists.txt:13 (include)
modules/world/CMakeLists.txt:50 (include_one_module)
I get the following error when running the build:
cmake --build "/opencv/build" --target INSTALL --config Release
make: *** No rule to make target 'INSTALL'. Stop.
Any thoughts on what to change?
itd be nice to specify cuda version since 12 seems to not work..?
I just did it with newest version of opencv and 12.1 a couple of days ago
Getting an error when importing cv2 in Python 3.10: Traceback (most recent call last):
File "", line 1, in
File "C:\ProgramData\Anaconda3\lib\site-packages\cv2\__init__.py", line 181, in
bootstrap()
File "C:\ProgramData\Anaconda3\lib\site-packages\cv2\__init__.py", line 112, in bootstrap
load_first_config([
File "C:\ProgramData\Anaconda3\lib\site-packages\cv2\__init__.py", line 109, in load_first_config
raise ImportError('OpenCV loader: missing configuration file: {}. Check OpenCV installation.'.format(fnames))
ImportError: OpenCV loader: missing configuration file: ['config-3.9.py', 'config-3.py']. Check OpenCV installation.
am getting DLL load failed while importing cv2: The specified module could not be found.
U need to install it again
@@NicolaiAI thanks for replay, the problem was caused do numpy version miss match
Yeah often mismatch from other installed dependencies afterwards
first: Sorry for spamming into your comment setcion.
second. I could fix the cudnn error (had to copy it into the specific folders of the cuda-installation)
third: Now i get this error: CUDA: OpenCV requires enabled 'cudev' module from 'opencv_contrib'
the build installation simpy ends in between for me any help
Have you solved the problem?
Sorry but the step at 6:50 was way too fast. Can u explain how i get the correct number with a certain graphics card? E.G. i work with a RTX 3050 mobile. How to set the correct number at arch bin ? Or is this step not important?
can i provide to you my errors to make sure i didn't do anything wrong?
errors from cmake configuration output and visual studio build output
I was able to build it but did not include the cudnn files, Once I tried adding them I keep getting this build error
CMake Error at cuda_compile_1_generated_gpu_mat.cu.obj.Release.cmake:220 (message):
Error generating
Using 4.5.2 and 11.3.
Any advice? I found old github posts mentioning changing the detectcuda file, but this one is completely different.
i have the same issue, you can just untick cudnn if you dont need to use neural network stuff, but if you do, i read online that after you copy the bin, lib, and include files into the corresponding CUDA directories, you need to restart and check if it works, some were saying you need to include the path in widnows, tried that but didnt change much
Why can't we simply download a prebuilt one?
Old versions and you can't customise your installation. Also prebuilt ones does not work on python and on all platforms often
Hello there. Im stuck at 6:13. It does not show me Cuda Fast math at this point. Which step did i miss
Did u install Cuda correctly?
@@NicolaiAI does it matter which version i do install? For visual studio at the point of release only the 2019 was supported, but meanwhile it supports (at least it says in the gui) 2022. How is it with Cuda? I installed the normal Cuda-package already but im unsure about cuDNN. Is there a tutorial for that?
U can only use 2019. I couldn’t get it to work with 2022. If u don’t need dnn u can just skip or else there is a link for the dnn module that u can download. I have a video about OpenCV gpu on this channel that covers that part. It’s around 25 min long
@@NicolaiAI Can u link it maybe? So i installed the Cuda Package, i also copied my CUdnn files to the folder suggested at the installation guide @nvdia. But i get the message "Could NOT find CUDNN (missing: CUDNN_LIBRARY CUDNN_INCLUDE_DIR) (Required is at least version "7.5")"
The only step i didnt do during the installation is adding cuDNN to my visual studio project (Step 5 in the cudnn tutorial)
Also i have to mention i did use OpenCV 4.6. Do i need to use 4.5.2 ?
Edit: Meanwhile i also followed the steps to integrate cuda into Visual Studio. Although im not sure if have done it correctly. However i still get the same error message. I am clueless why the installation progress for cuda has to be even more complicated than installing drivers 25 years ago (from Nvidias side, your explanation was very helpful although i still couldnt make it run)
edit 2: meanwhile i can see the fast math option for cuda
Helo, Your video is very helpful, thank you! I get such an error when loading the configuration file:
CMakeLists.txt:26 (message):
cudacodec::VideoReader requires Nvidia Video Codec SDK. Please resolve
dependency or disable WITH_NVCUVID=OFF
I have downloaded the NVIDIA Video Codec SDK, but I don't know which files to copy to where to copy them to opencv
Update1: I solved it according to the description below, copied the necessary files. The configuration and generation runs without errors. I'm in Venv and then started the installation command. This also ran. However, the python in venv does not see the cuda. I am in Windows 10.
i have succeeded to perform all processes and i got the result from this code
>>> import cv2
>>> from cv2 import cuda
>>> cuda.printCudaDeviceInfo(0)
and detected my external/extended GPU in my laptop
but when i run the program and i saw prom task manager, why only CPU that has process until 70% and GPU0 (internal/integrated/GPUIntel) has low progress around 10% and my extended GPU (NVIDIA) didnt have any progress?
can you help explain it why? because its look like my NVIDIA didnt work when i run the program
thanks for your answer
Thats because u are not running anything on the gpu yet
@@NicolaiAI can you give me a code sample or tutorial to test my NVIDIA gpu in my laptop, or to run some applications or systems using my NVIDIA gpu
thanks for your response
@@ardaaldoe4984 i have a course covering everything about how to use the gpu with opencv and even numpy on the gpu
Hi. I could successfully follow this,thanks a lot.... But I am getting this error when I write import cv2.
Traceback (most recent call last):
File "", line 1, in
File "C:\Users\parth\AppData\Local\Programs\Python\Python37\lib\site-packages\cv2\__init__.py", line 181, in
bootstrap()
File "C:\Users\parth\AppData\Local\Programs\Python\Python37\lib\site-packages\cv2\__init__.py", line 153, in bootstrap
native_module = importlib.import_module("cv2")
File "C:\Users\parth\AppData\Local\Programs\Python\Python37\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ImportError: DLL load failed: The specified module could not be found.
Could you please help me with this.
Thanks in advance. i was seeing
thx
Ur welcome!
Python (for build): C:\Users\jeg\anaconda3\python.exe does show, but not the "python 3"/lines. any hints? Note: i had to use visual studio 2017, 2019 did not show as an option in cmake-gui (2019 was installed originally)
Does it show numpy path? If not, u should upgrade numpy and that should fix it
@@NicolaiAI I have the same problem.. It only shows Python (for build) but not Python 3 with the lines below (including Numpy), I made 100% sure that numpy is on the latest version and yet the error still persists. //EDIT: I manually added all of the Paths but when I try to install the configuration, it takes like 40 seconds and doesn't even come to "-installing" as seen in the end of your installation.
@@lukasTHEwise having same issue, was it resolved for you?
@@shreyashkhedkar2491 Make sure you have installed python on ur system drive, that was my problem at least..
Plz .I need your help to set cuda GPU.
Hi have u seen the opencv course I’ve made. I go over all of it and provide support in there
Thanks for the great tutorial, it's very easy to follow!
Everything works as expected, however, I'm getting this error while trying to print cuda device info
cuda.printCudaDeviceInfo(0)
Traceback (most recent call last):
File "", line 1, in
cv2.error: OpenCV(4.7.0) D:\a\opencv-python\opencv-python\opencv\modules\core\include\opencv2/core/private.cuda.hpp:106: error: (-216:No CUDA support) The library is compiled without CUDA support in function 'throw_no_cuda'
Do you know what causes the error and how to resolve it?
Thanks in advance :)
which gpu u have
@@GamingXYT I too am getting this exact same error, but with OpenCV 4.8.0. I know the CUDA compatibility version is 8.6, because I have RTX 3050.
No module named cv2, please help🥺
Did u verify that it was able to detect Python in the Cmake configurations?
I fix the cv2, but after that another error 'throw_no_cuda' please help🙏
@@NicolaiAI I have same error after done the install process, Cmake detect Python in configuratión process, please help :c
@@carlzmarasiganz5353 How did you manage to solve de import cv2 error?
(base) PS C:\WINDOWS\system32> python
Python 3.10.11 | packaged by Anaconda, Inc. | (main, Apr 20 2023, 18:56:50) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> from cv2 import cuda
Traceback (most recent call last):
File "", line 1, in
ImportError: cannot import name 'cuda' from 'cv2' (unknown location)
>>>
Hello, thanks for your tutorial ! It worked for most gpu with cv2 codes i tested. But it didn't worked when i tried to activate yolo gpu with cv2.dnn.DNN_BACKEND_CUDA and cv2.dnn.DNN_TARGET_CUDA parameters. I think it's because i get too many warning messages on visual studio when i'm building the package (thousands of warnings about opencv_world). I want to know if you could upload somewhere your cv2 package file please. I want to compare the files i build and the ones you build and understand what is going wrong for me. Maybe is something missing when i try to compile.
I have another tutorial here on the channel where I also build it with dnn support. That’s another step which is not covered in this video.
@@The-Dark-Tower my longer video with the installation. But u can basically just search for dnn in cmake and set the flag
Which CUDA version did you use? I managed to generate everything as you, same OpenCV and Visual Studio versions, but i'm struggling with the final release part. My cmd doesn't do cmake -build "C:\your_path\build" --target INSTALL --config Release. I saw that it's possible to do this with visual Studio. So i openned my Visual Studio 2019 and runned it. But around the line 27 it begins to fail. The most failable modules are related to OpenCV_World. By the end says that 26 compilations succeded and 99 failed. My cuda is the last released one. So i wonder if that's the problem. Or if it's the fact that i did the last part without cmd.
I’m using 11.3
you need to create a new path to variable system for cmake, so the prompt can recognize the cmake
i passed every procedure and replicates the steps and no errors, but when checking it "import cv2" it appears no Module named 'cv2' why?
Did you fixed?
es normal que tarde tanto?
Does this work with Amd gpus?
Nope not yet. Only cuda
sht didnt work
ive done this tutorial over and over again, yet still I'm getting this:
NVIDIA CUDA: YES (ver 12.2, CUFFT CUBLAS)
NVIDIA GPU arch: 50 52 60 61 70 75 80 86 89 90
NVIDIA PTX archs:
cuDNN: YES (ver 8.1.0)
OpenCL: YES (NVD3D11)
Include path: C:/opencv-4.8.0/3rdparty/include/opencl/1.2
Link libraries: Dynamic load
Python (for build): C:/Users/*user*/anaconda3/python.exe
Java:
ant: NO
Java: YES (ver 20.0.1)
JNI: C:/Program Files/Java/jdk-20/include C:/Program Files/Java/jdk-20/include/win32 C:/Program Files/Java/jdk-20/include
Java wrappers: NO
Java tests: NO
Install to: C:/opencv-4.8.0/build/install
I have followed this instruction exactly but mid INSTALL got this error when trying to build the opencv_core460.lib from opencv_core.vcsproj
nvcc fatal : Could not set up the environment for Microsoft Visual Studio using 'C:/Program Files (x86)/Microsoft V
isual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/../../../../../../../VC/Auxiliary/Build/vcvars6
4.bat'
Nvm, if anyone encounter this error. Ensure environment path has no weird symbols like double quotes or "/". Also to run the cmake command from cmd admin instead of power shell