OpenCV GPU: Installing OpenCV with GPU for Python using VS Code and CUDA
Вставка
- Опубліковано 14 лип 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-nielsen.com/aicareer (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 📝 we are going to Install and Build OpenCV with GPU for Python. We are going to use NVIDIA Cuda to run our OpenCV programs on an NVIDIA GPU. We will go over the installation process for all the required programs and files. We will then use CMake to do the configuration of the OpenCV source files and then build them with GPU support later on. At the end of the video, I'll show how we can include the OpenCV library with GPU support in Visual Studio Code and see how we can verify that everything is set up correctly.
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-nielsen.com/nncode
_____________________________________________________________
💻💰🛠️ High Earner AI Career Program: www.nicolai-nielsen.com/aicareer
⚙️ Real-world AI Technical Courses: (www.nicos-school.com)
📗 OpenCV GPU in Python: www.nicos-school.com/p/opencv...
📕 YOLOv7 Object Detection: www.nicos-school.com/p/yolov7...
📒 Transformer & Segmentation: www.nicos-school.com/p/transf...
📙 YOLOv8 Object Tracking: www.nicos-school.com/p/yolov8...
📘 Research Paper Implementation: www.nicos-school.com/p/resear...
📔 CustomGPT: www.nicos-school.com/p/custom...
_____________________________________________________________
📞 Connect with Me:
🌳 linktr.ee/nicolainielsen
🌍 My Website: www.nicolai-nielsen.com/
🤖 GitHub: github.com/niconielsen32
👉 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
_____________________________________________________________
Timestamps:
0:00 - Overview
2:30 - Download OpenCV Source
3:37 - Anaconda and Python
7:33 - CMake Configuration
19:34 - Verify Installation and VSCode Setup Python
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
Thanks man, After many tutorial videos, and many text tutorial, This is the one is work !!
Thank you !!
Thank you for watching! I really appreciate it and glad that it helped u
Dude, you are some kind of a genius. I could spend the rest of my life trying to figure all this out. All your steps worked flawlessly (I did run into some issues with cudnn but that had nothing to do with your instructions. Very well done!
Thanks a lot for watching and the nice words! Glad that it helped u out
Your video was very helpful! I was able to compile with no problems :) Thank you so much!
Thanks for watching! Glad that it could help u
En af det bedste tutorial for installation af python og cuda.
thanks so much for this guide! helped me out a ton
Thank you so much! Glad that it helped u out
Thanks man, I am almost done installing this. rn I am waiting for another hour to complete this all.
Tip for others : Strictly follow the requirements with versions (I mean everything VS, numpy, python, all of them). I tried this to install on vs 15 2017 and struggled alot. there were also many problems while installing because of too many python interpreters listed on environment vairables, later I had to remove all those which weren't needed like 3.9 and 2.7. finally now it worked. and almost there to complete all steps.
Thanks for watching! Glad that u have installed it now
Many thanks man! very well explained.
Thank you very much! Really appreciate it
Thanks so much for this, this is the first tutorial that helped me actually achieve this! :)
For some reason, it doesn't work for OpenCV 4.5.4, but 4.5.2 will do just fine for now
Thanks for watching! Really glad that i could help u
Thank you for teaching. This video let me done 😀
Thanks for watching! Glad that it could help
Great video, thank you!
Thank you very much! Really appreciate it
Perfectly solves my problem!!!!
Great! Glad that it could help u
Thanks U, for your video, so detail, and true
Thank you very much! Really appreciate it
Thanks brother. video was very helpful.
Thanks a lot for watching!
Thanks a lot!
Thanks for watching!
Thanks 👌🏾🔥
Thanks for watching!
Thank you very much
Thanks for watching! Hope u can use it
Thank!
Thanks for watching!
Nice
Thank you!
Thanks for this great tutorial! I have a question: To install this in an anaconda environment, i just have to use path of python file and libs files of this environment? I did it today and i had a problem: this only install the "Headless" version of opencv...
Hi..Thank you so much for this video man.. your explanation for the Anaconda path saved me a lot.. that was so useful for me. but once i start with your command in Anaconda prompt with cmake... that was not working for me. I getting an error like "there is no directory like cmake" I got stuck here.. and what is the meaning of INSTALL in that command? can you please explain this..? I looking forward to your reply. Thank you.
I have created other virtual env(python3.8) in my anaconda but different python version with base environment (python3.9). I have changed path of PYTHON3_LIBRARY, but CMake always keep the same path with base environment. (By the way, I reinstall my the same anaconda version as you and it worked ! )
Yeah having multiple python installations on ur pc can cause some problems
Hi! Thank you for your video. Really helps.
I wonder how can I install cv2 in other environments using the same Python version as compiled (3.8 for my case)?????
Thank you very much! Really appreciate it. If u are going to use it in different or other environments u will unfortunately have to do the process over again unless u have the exact same versions and can copy it somehow, but that might cause more pain than doing it over again. After a couple times it takes 5 min to do 🙂
and if the build folder is in a different place. how will conda add this package to the environment?
at the end i've this error on anaconda "ModuleNotFoundError: No module named 'cv2'"
I can't get it why ..could you help me please ?
In case if I need to install it on another Anaconda Environment do I have to repeat the whole process again or (Since it takes lot of time) can I install it through some copy/paste or command... plz help, and thanks for the tutorial
Thank you for watching. If u install another base version u should be fine. But if u want to create virtuel environments then u would have to do it over again
@@NicolaiAI do it over again.... noooooooooooooooooooooooooooooooooooooo
Thanks for your video. I'd like to know if there is any documentation one can refer to if he wants to find how to use these cuda based opencv functions using Python. I guess this still hasn't been well documented because it's not common practice yet, but perhaps you know some useful sources one can refer to in this regard? Thanks.
Thanks for watching! In the OpenCV official documentation they actually have the python method for cuda as well. I'll create a tutorial both in c++ and python with the cuda module, so stay tuned in the near future here
@@NicolaiAI that's great news!
Hi sir, Idk what did I do wrong. My cmaketarget after i build the install, it only show 1 success with 0 fail. In your case its 2 success. Then, when I try verify whether I installed opencv or no, it shows no. (cannot import cv2). Do you know problem like this this?
All configure and build steps went smooth but importation of cv2 fails (Also I got quite a few errors in the Release command on CMD) Please Help?
hello, I'm trying to install it with python 3.9, but when I type cv2.__version__ it gives version 4.5.5. opencv is not installed in anaconda
I'm able to get through the entire build process but once I try to import it in python I just get errors when I import it "ImportError: DLL load failed while importing cv2: The specified module could not be found. ". It seems that the proper files have been generated in the site-packages folder and my build directory. I've been at this for two days now.
i aslo got the same problem
Just reinstall anaconda
Hello i've gtx 1650 ti on my notebook when i try to tick option WITH_CUDA it gives me an error what should i do ?
Thank you so much for the amazing tutorial!! I might have a stupid question though...as I'm completely new to this, but what is the difference between this method and just downloading everything with 'pip' ??
installing opencv through pip will not provide you with GPU access. GPU functionalities are only enabled by installing opencv from source. In this case he added those functionalities to a specific python pre-built environment called anaconda but you can build opencv into your own virtual environment as well.
Hey, my generic Python installation has version 3.7 while my anaconda one has version 3.6. In CMAKE I specify the path to the anaconda 3.6 version, but it keeps configuring it to 3.7 because it keeps referencing the "/libs/python37.lib" file in generic installation even though I specify that file in anaconda3.... Ultimately that leads to import failure with CV2. Any ideas on how to make sure it is linking to the correct Library in the config file?
you solved it?
When I use cuda.printCudaDeviceInfo(0), I got the error (-216:No CUDA support) The library is compiled without CUDA support in function 'throw_no_cuda'
Looks like the cmake configuration hasn't been done correctly :(
Have you solved this issue now? Can you help me with it
Same problem
yeah same here
why didn't we install cuda and cudann
Hy!
I got a problem to include python3 into my project.
I've done the same operation, but it's still unavailable, and I don't know why.
Could you try to help me ?
Traceback (most recent call last):
File "", line 1, in
cv2.error: OpenCV(4.9.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 getting this error, how to solve this
Great vid, just a question, I'm having trouble where the anaconda prompt shows different version of python which is 3.9.7 but I've installed the python 3.9.9..I can't import the cv2 because of it. How do I solve this? Would appreciate any response, thanks!
hello did you solve it
Visual Studio 16 2019
could not find any instance of Visual Studio. I already have visual studio
Thanks!
Thanks for watching!
Hi, thanks for the video. I am getting the following error:
CMake Warning at cmake/OpenCVFindLibsPerf.cmake:45 (message):
OpenCV is not able to find/configure CUDA SDK (required by WITH_CUDA).
CUDA support will be disabled in OpenCV build.
To eliminate this warning remove WITH_CUDA=ON CMake configuration option.
Call Stack (most recent call first):
CMakeLists.txt:712 (include)
But I have installed CUDA and cuDNN. Any ideas as to why? Thanks
I had this this issue for the entire day, I was able to finally making it work with OPENCV 4.5.5 CUDA 11.4 and cuDNN 8.2.4
Hello, the python libraries : NO and install path :- , do you know how to fix it? i have already tried manually written the values but still wont work
are u using anaconda? Try with that then and choose add to path during installation
@@NicolaiAI i reinstalled anaconda and cmaker, all good now thanks for the reply !
Great!
Thank you for your tutorial. I have a question if installed successfully then every task with OpenCV will compute on GPUs, rights? (example cv2.bilateralFilter())
Thanks for watching! U will need to upload the frames/images to the GPU before calling the functions and then it will run og the GPU. I have some examples here on the channel under the OpenCV GPU Cuda tutorial
@@NicolaiAI thank you very much
@@NicolaiAI what a about training a model. Will it train the model with gpu?
@@ahuman5383 u can't train models with opencv only deploy
@@NicolaiAI oh so when I train the model like for drowsiness detection, it will use cpu? Unless i use google colab?
If I want to downgrade opencv from 4.5.4 to 4.5.3, do I have to uninstall 4.5.4 first? Because I am not sure how I uninstall a package that wasn't installed from pip. Currently, running these commands in cmd: 'import cv2' and 'cv2.__version__' returns 4.5.4, if I follow these exact steps again and build 4.5.3 will 'cv2.__version__' change to 4.5.3?
hello did you solve it
15:06 When I select all necessary for Cuda and configuration show error "error in configuration process project files may be invalid" how can I solve this ??
Sounds odd, it will work if u do everything step by step from the video. Seems like there is something wrong with the files
I do have the same issue. Do you have a fix? :/
Had the same issue. Fixed it by installing the next workloads in Visual Studio Installer:
- Desktop development with C++
- Universal Windows Platform development
On the numpy part I get "ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
daal4py 2021.3.0 requires daal==2021.2.3, which is not installed.
numba 0.54.1 requires numpy=1.17, but you have numpy 1.22.2 which is incompatible." Is this okay?
Have you solved that?
I have installed open cv 4.5.2 in vs code .Now what should I write to import it like import cv2 or something else. Plz reply...
I go over all the steps in the video and show it in vscode
@@NicolaiAI Oh yes I got it . Thanks buddy ❤️
Happy to help!
When I ran "cmake --build "C:\your_path\build" --target INSTALL --config Release", it kept showing me this:
warning #1394-D: field
of class type without a DLL interface used in a class with a DLL interface
I always get this error :
D:\OpenCVGPU\opencv-4.x\modules\core\include\opencv2/core/cuda/common.hpp(101,27): error.....and so on (There are so many error related to common.hpp)
Does anybody know how to fix this? (I am using Windows 11)
12:17 after i have conf for the second time error has gone but nothing have changed unavilable variables still the same (java,pyth2,pyth3)
@The coding Library Dude i know what is the problem ( Cmake cant find LApack ) i have already downloaded lapack but i dont know what i should do
Did you find a solution? I have the same problem
@@MS-fk8ec I had python 3.7 installed so i put path to it and dat cuz the problem , you have to install anaconda
@@mostafael-sayed4244 I do have Conda, removed the other (non Conda python) yet still faced the issue, it turned I out it the Conda installation had to use Conda as my primary python
@@MS-fk8ec yeah you should put anaconda python in top in enviornment
I've got a problem when I'm building & installing opencv from cmake : the build can work but it doesn't installed , plz help and thanks for the great tutorial !!
Hi make sure to follow all the steps one by one and then it will work for u. Thanks for watching!
Thank you, everything worked perfectly until I typed this command: cmake --build "C:\Users\User\build" --target INSTALL --config Release
and it popped up error like this.
'cmake' is not recognized as an internal or external command,
operable program or batch file.
Could you help my with this. Thank you again sir!
Make sure u chose to add cmake to ur path during installation of cmake or else u will have to add it to the path urself
@@NicolaiAI thank you sir.
Happy to help! Thanks for watching
Today I've successfully installed and followed all the steps but when I run my code it turned out:
"Could not load library cudnn_cnn_infer64_8.dll. Error code 126
Please make sure cudnn_cnn_infer64_8.dll is in your library path!"
Could you help me with this, sir. Thank you.
By the way my Cuda is 11.5 and cuDnn 8.3.
Will the GTX 1650 graphics card work for me or should I go with the i5-9300h?
Almost all GPUs would be an improvement over a CPU
i did everything like you showed, but i can't get python3 excluded from "Unavailable" under OpenCV modules
same for me, did you fix it?
Same here
how can i go this with anaconda environment? (i have a problem because latest anaconda version comes with python version 3.9 in base environment)
Have you found a solution?
I built it with python 3.6 base environment then changed all the values for python in cmake, which makes it so it is built for the anaconda environment instead. Another thing you can try out is editing the PATH in environment variables and add the path to anaconda's python.
It did not work for me. No module named 'cv2'. What did I do wrong?
Not installed properly then since it can't find it at all. Make sure to choose the correct interpreter in vs code too
command is giving error msbuild error MSB1009: Project file does not exist.
please help. Thanks in advance
You forgot to click "Generate" inside of Cmake after the configurations were set.
@@archheresiarch9342 Thanks for this, it helped me :)
When i type in cmd prompt - cmake build “C:\Users\mike\opencv-4.5.2\build” -target INSTALL - config Release. I get error cmake is not recognizable as an internal/external command. I saw in comments someone had problem also but unsure on fix. My CMake is installed in defaulf MyPrograms.
How can i fix this please?
Is cmake in ur path environmental variables for all users? Are u in a standard command prompt og anaconda prompt
@@NicolaiAI command prompt. I typed this set PATH=C:\Program files\CMake\bin\;%PATH% per google and new error is MSBUILD: error MSB1008: only one project can be specified.
@@NicolaiAI standard cmd prompt and unsure i used default install settings on cmake
Think u have to check off a box during installation to add it to the path
Is there a workaround or i have to start over?
10:43 It doesn't work for me, idk why, please help me
How do I do this without nvidia graphics card? (Intel UHD 630)
U simply can't
@@NicolaiAI Awww, I have to wait for gpu prices to come down.
Hello, during installation few files throws up an error " #error:
This file was generated by an older version of protoc which is (compiling source file C:\Users
itis\Opencvpython\open
cv-4.5.2\modules\dnn\misc\tensorflow\attr_value.pb.cc)". Please help me out and let me know what to do
After doing the steps shown in 15:07 , it says Error in configuration process project files might be invalid.
and i notice it says
NVIDIA CUDA: NO
CUDNN: NO
I do have the same issue. Do you have a fix? :/
cant use gpu with amd gpu¿?
Nope u will need a cuda GPU
Hi, I followed the steps till the end. But I receive error when I write import cv2 to anaconda prompt. It debugged ModuleNotFoundError.
Addition to this there is no config 3.9 file in cv2 directory.
I did realize Justin Bieber was so knowledgeable about these things haha
Haha thanks for watching! Really appreciate it
❌"... fatal error c1189 This file was generated by an older version of protoc which is (...) [...]" while building with cmake in the command prompt ❌
After hours wasted trying the impossible to solve this error I was FINALLY able to solve it by removing the "protobuf" library from my Anaconda environment by simply executing: "conda remove protobuf" from Anaconda Prompt (this took a few minutes for Anaconda Prompt to execute).
So, if you're following the tutorial step-by-step you will NOT encounter this problem, but if like me you already have Anaconda installed, check weather you have the library "protobuf" in the Anaconda venv where you are building OpenCV. In this case, remove it. I tried many other workarounds but this is the only one that worked. If then you need to have "protobuf" in your venv you can always re-install it.
And of course, thank you Nicolai for the great tutorial, it really helped dealing with this tedious installing procedure 😊💖
It sucks having spent 1-2 hours into this and after everything, seeing "No module named cv2"". :/
If u did every step correct and check the python path during configuration in cmake it only takes 5 min. Make sure it detects python before installing
Does this work with AMD gpus?
Hello, I have a problem and I can't fix the problem. I have sent you an email. Could you please read my mail please? 😭😭😭😭
A very interesting OpenCV video. I am curious about using OpenCV on the new Orange Pi-5 and hope that it will run faster than the Raspberry Pi-4? Any suggestions would be helpful. ...Amazon $99.99... Orange Pi 5B 4GB Rockchip RK3588S 8 Core 64 Bit Wi-Fi6, BT5.0 Single Board Computer with 32GB eMMC, 2.4GHz Frequency Open Source Development Board Run Orange Pi OS, Android, Debian, Ubuntu (OPi 5B 4G32G) ARM Mali-G610 MP4 GPU 😎 Thank you.
nooooo, after the cmake compile process,it is not install to the anaconda python🥲correctly .and there's no install file in the build library,(using lateset cmake and visual studio version
Great video and easy to follow thanks. Compiled fine thanks - Was just a bit confused with cuda version vs computer compatibilty version. Here's a link if anyone needs to find their version en.wikipedia.org/wiki/CUDA#GPUs_supported
Thanks man! Happy that it worked out
is it just me or does it just stop installing midway and instead of ending with "installing...: blah blah blah" , it just ends with something like "transpose.cu"
U should just let it run. It can take 2 hours+
@@NicolaiAI thanks for replying! I did, I left it for 4 hours several times. But I think it was an error when configuring in cmake anyways because it gave me an error that said “opencv does not recognise MSVC:”1932”” 1932 being the version for vs 2022. So I am currently trying to download vs 2019
@@mj9207 I think I did it with 2019
PLZ. HELP. ERROR WHILE INSTALLING
CUSTOMBUILD : nvcc warning : The 'compute_35', 'compute_37', 'compute_50', 'sm_35', 'sm_37' and 'sm_50' architectures a
re deprecated, and may be removed in a future release (Use -Wno-deprecated-gpu-targets to suppress warning). [F:\elvict
o\cmake\4.5.2\build\modules\world\opencv_world.vcxproj]
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'
CMake Error at cuda_compile_1_generated_gpu_mat.cu.obj.Release.cmake:220 (message):
Error generating
F:/elvicto/cmake/4.5.2/build/modules/world/CMakeFiles/cuda_compile_1.dir/__/core/src/cuda/Release/cuda_compile_1_ge
nerated_gpu_mat.cu.obj
even though i upgraded numpy... still python3 is unavailable what should i do....?
Are u using base python installation or anaconda?
@@NicolaiAI anaconda
Do u have conda in ur environmental variables? And can u see the path to the python installation in the cmake configuration as i show in the video?
@@NicolaiAI yes and i found that it could not able to find the pkgconfig in bulid folder here ......VTK is not found. Please set -DVTK_DIR in CMake to VTK build directory, or to VTK install subdirectory with VTKConfig.cmake file
OpenCV Python: during development append to PYTHONPATH: C:/coding/opencvpyhton/bulid/python_loader
Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE)
Module opencv_alphamat disabled because the following dependencies are not found: Eigen
Caffe: NO
Protobuf: NO
Glog: NO
freetype2: NO
harfbuzz: NO
Julia not found. Not compiling Julia Bindings.
OpenCV Python: during development append to PYTHONPATH: C:/coding/opencvpyhton/bulid/python_loader
Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE)