Build and install OpenCV from source with CUDA and cuDNN support

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
all right in this video i'm going to show you how you can build and install opencv with nvidia code support we're going to build opencv dnn with cu dnn as well all right so we are on a fresh ubuntu 20.04 installation here um i didn't manually install the graphic driver nvidia driver here it automatically installed it when i you know check the install third party software in the installation period if i check nvidia settings here you can see it's running nvidia drive already this is not the open source driver this is the proprietary driver you have to make sure that because it's not going to work with open source driver all right let's jump to cuda installation you will find a link to this documentation in the video description first i'm going to download cuda and you can just click on download the nvidia kuda tool kit and here you can go to cuda downloads select linux 64 architecture then i'm going to select ubuntu because i'm running ubuntu version is 20.04 and i'm just going to get this dev package right here so to download the package all you have to do is run this command make sure you have wget installed with ubuntu i think it comes with ubuntu i can just check that w get version yep it's already there so just run this command and it will download the date package all right i'm just going to go back because i already have it here inside nvidia this is the cuda depth package all right now i'm just going to go back to the original documentation and let's check out pre installation actions so you need to have a cuda capable gpu um i have a gtx 1060. so that's a kuda capable gpu that's not something i should worry about and verify you have supported version of linux you can just check that out i'm using latest that's going to be fine so i'm just going to continue to the next one verify the system has gcc installed we can just quickly check that using gcc version okay that's not installed now i'm just going to install that using this command all right gcc installation is done just to verify let's run gcc version now all right right now we are using gcc 9.3.0 you may have to check gcc compatible version for your cuda release otherwise you may run into some issues when you are compiling your application all right now gcc is done let's go to the next requirement or prerequisite verify the system has correct kernel headers and development packages installed scroll down to ubuntu so this is all you have to run to install hit kernel headers you probably already have it if you're using 20.04 so i already have it and let's continue now you should download cuda but we already have it so i'm just going to jump to package manager installation and i'm going i'm going to click on ubuntu okay now we are going to install the package so let's navigate to the folder and right click open terminal here and let's do sudo dpkg dash i and cuda repo hit tab to auto complete and hit enter enter the password all right that is done now it shows a warning the public cuda gpg does not appear to be installed and we are going to install that next so it shows basically the command that you that you need to run and i'm just going to copy this paste it here and hit enter okay that's done so we installed the gpg key now let's jump to the next step update apt repository cache and i'm just going to copy this command and update okay we just updated the package cache and we are going to install cuda next okay that's done i believe that's the last step here we have yes so we are done with the kuda installation now i'm just going to restart the pc so be right back all right i'm back now you want to make sure that you don't have any issues with the graphic driver you have installed previously after the code installation otherwise you will have to resolve that first before continuing okay now we don't need these two tabs let's continue with this udn and installation before you download cu dnn you have to log into the nvidia developer program so go ahead and do that first if not registered you can register using gmail account once you have done that you can just go to cu dnn home page and click on cu dnn here i'm going to agree to the terms here you want to make sure that you're downloading the correct version for the cuda installation you have on your system to confirm that you can get the kuda version now if you run v and cc that's not going to be available by defaults for some reason you know the the bin is not in the path environment variable but i'm just going to mention oh the set the direct path to that binary that is user local cuda bin and vncc and let's get the version here oops i may have sorry it's nv cc version and we are running 11.3 okay this is the version i want here i'm just going to get dev packages because i'm running ubuntu i'm going to download runtime library developer library as well as the code samples if you don't want this just ignore this one right here but other two download them i already have them so i'm not going to download them again these are the three the packages from that page and we are just going to install all of them so let's run sudo dpkg i let's pass the first day package oops let me undo that f2 control copy then let's go back and paste it here okay my caps lock was on let's run the next day package which is dew package controller copy and sudo bpk g dash i then paste the package now let's install the code samples as well same thing but a different depth package all right now we are done with cu dnn installation it's just going to place some header files and libraries in the system all right now i'm going to install git because i want to clone opencv and opencv contrib repositories so let's do sudo at install git once kit is installed you can go to opencv github repository and copy the url go back and just type git clone and paste the url to clone the repository do the same for opencv contrib as well i already have them so i'm just going to open that i have both of them in the same directory and i'm going to create a new folder called build now to build the project i'm going to need cmake so let's install that as well sudo apt install cmake i'm just going to install cmake gui asl it's easier to use we can now fire up cmake gui first i'm going to select the source directory to open cv opencv directory open that next we are going to select the build directory to the one we created this one right here now hit configure and select the negative compiler and unix make file all right before anything i'm going to select the path to extra modules so search for extra and for the opencv extra modules path select the opencv contrib modules path you have to go into modules and select okay now let's search for cuda enable opencv dnn underscore cuda sls with cuda flags now let's search for python because i'll be using opencv with python here you need to set these paths you need to set the executable um you can quickly search that using which python 3 if i can type that correctly w ch this will give you the path to python 3. now you have this now to get the python 3 include dir path i found a question in stackoverflow so run this in python let's open up python interpreter python3 let's import this stuff and let's pretty print get paths and here we have include a path to include directory just copy this one and paste it for the flag now next up we have python 3 library i just used find command to find that let me close this i used find start starting from root and i include the name it was lib python and something so let's output all that to a file called out now let's useless out to read the file and here you will find dot so file um so we have multiple of multiple files but this is the one i'm going to use and copy the path here paste it to the library again it should be lib python the version the python version you have and dot so file because it's a library next up we have python 3 numpy include directories of all you need to install pip so let's do sudo apt install pip after that you can install numpy use pip to install numpy sudo pip install numpy once that's done you can find the path to numpy include directory let's use find command again find start from root name of the file is numpy oops numpy again i'm going to use the same file to write output let's out and we have include directory you don't need to copy this numpy directory as well just copy up to include this one right here and paste the path now to set the package directory you can use the same path you have used for numpy but copy up to this packages copy this you know use a local lib python um directory then dist packages copy up to this and paste it here just like that okay now i'm going to hit configure okay we are done with the second level configuration i'm just going to remove the search we still have flags in red color so we are not done next up we are going to set arch bin so let's search for arch here you can see we have all all type of um versions here but you only need to include the version that you want the support for now i'll open up wikipedia cuda page and here if you scroll down to this table and find the graphic card you have i have a gt gtx 1060 and the architectures are used in gtx 1060 is pascal and the arch bin version is 6.1 you can either set the arch bin version here manually to 6 6.1 or else what you can do is you can search for cuda and here you will find cool generation and select pascal here then hit configure again you can um choose either version to configure arch bin you can hit configure now if you look at the ash bin again you can see we have uh 6.0 and 6.1 i'm not sure why it's selecting 6.0 um yeah i'm not sure about that but if you only have 6.1 for gtx 1060 it it is still going to work now you can hit generate we no longer have flags in red color so hit generate now the generation is done now we can continue to build the project let's close cmec go to the build directory open up a terminal window here and let's run make to build the project now i'm going to add time just to check how long it's taking and let's run make i'm going to use four processors to build this project you can check how many cores you have and add the number here so we can so we can build sorry we can divide the build process now i'm going to hit enter this is going to take some time on my machine it's taking almost one hour so i'm going to let it build all right we are finally done building opencv it took 52 minutes on my pc now let's install opencv to do that i'm going to run sudo make install the same way you can uninstall if you want to sudo make uninstall so we are done installing all right now let's validate that we have opencv with kudo support for that i'm going to fire up python3 let's import opencv and i'm going to call cv2 cuda get cuda enabled device count and this should return one because i have one graphic card and there you go we have build and installed opencv with coda and cu dnn support so that's it thanks for watching have a nice day
Info
Channel: s1n7ax
Views: 12,340
Rating: undefined out of 5
Keywords: opencv, opencv-python, how to, guide, installation guide, build and install from source, cuda, cuDNN, CUDA, nvidia CUDA, Nvidia cuDNN, opencv dnn, build from source code, compile opencv, ubuntu 20.04, ubuntu
Id: whAFl-izD-4
Channel Id: undefined
Length: 20min 11sec (1211 seconds)
Published: Wed Jun 09 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.