How To Install and Build OpenCV C++ with NVIDIA CUDA GPU in Visual Studio Code

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys welcome to a new way in this computer vision tutorial in this video here we're going to install and build opencv the gpu so in this video here we're going to go over this installation process and how we can actually like build omsvi with gpu support here i'm going to show you like that we're actually able to use opencv gpu uh in cbos plus and visual studio code in this video here i'm going to create other videos where i'm going to show you how we can set up in both python and also some other different kind of ids like visual studio here and how we can use openstack with gpu in that way first of all we're going to join the discord server i'll link to it down in the description here and you come join us chat chat with us about computer vision deep learning artificial intelligence and so on you can also become a member of the channel here if you want to support the channel more than you're currently doing but just watching here with a small monthly and everything will go to create more and better quality content here on the channel so thank you guys so first of all here let's go over some of the steps here that we're going to cover in this year as well and i'm going to have the timestamps steps under the video here so like you can just skip through them if you have already have a cmake installed or like cuda and something like that but first of all here we need to install omcb the source files from opencv so we'll go into the github omcv repository and we'll download the source files and then we also need the opencv contrib um directory as well so we're going to use that to actually like be able to build almost aviva gpu support in cmake then we're going to install visual studio here um from like from scratch here where we need to specify that we want to to install it with the siebel plus development tool because we're going to use that to actually like be able to build the opencv source files with gpu support then we're going to install cuda and cool dnn from an nvidia's website so we can actually use the nvidia cuda uh drivers to actually able to use ohmsv with our gpu from nvidia then we're going to install cmx which which is what we're going to use to actually like be able to build homes we from the source files and together with the gpu support we can specify some different kind of things like for example like we can use a 5 math and all the different stuff like that or if you want to build it into release mode debug mode and so on then we're going to configure opencv with gpu and cmake we're going to build the source files with cmag as i just mentioned and then at the end we're going to set it up and test omcv with tpu support in visual studio code so i'm going to show you first of all how we can build build uh the source files from opencv with cmx so we have tpu support and then i'm going to show you how we can set them set it up in visual studio code and use opencv with a gpu so first of all here we will jump into the first installation page which is where we're going to uh took like like download the ohmsv source files from so we just go into the github repository here for opencv i'll link to everything down in the description so make sure to check those links out and you can just click on them and go to each of the individual installation pages and then just install all the things here that i'm going to go through with you now first of all here we're going to install the source files from opencv so we can see here that we have all the different kind of source files here that we need so we can go up here in the masters here and choose like a branch that we want so in this case here we can just go into the tags here for opencv and then we can choose the version of opencv where that we want to actually like be able to build from source files with gpu support and this would be here i'm just going to take the newest one which is 4.52 i'm just going to choose this one here and we will now go into this branch here with this newest version here of opencv again then we go over here to the right and just click uh that this download zip file here we're actually like going to download a zip file uh to our computer here the other thing we need to uh download here from from opencv's repository here in github we also need this contrib uh ohms omc um opencv files here where why are we actually going to use this module here because inside of these mod and this module over here we have some different kind of like setup for cuda uh with opencv need this we need to download this omcv underscore contrib here to actually like be able to use uh kura here with opencv so i'm just going back here into almost v um um cv here again and then we're just going to master here into tags and then we just choose the same version as we did with the suv so i'm just going to have this 4.52 and then i'm going over here downloading a zip file here again so now we actually have all the source files from osv and also the source file from opencv contrib that we're going to use to actually be able to to set or like build omcv with gpu support so now i have them down here i can show them in my folder and then we can see here that we're not just downloading here and they're both zipped so we're just going to extract all the files here in the download directory so now both the folders here have been extracted here and we can just then go in and create a new directory where i like want to build the source files from osv here so i'm just going to open up a new tab here in the file explorer and then i'm going into my user directory so i'm just going to user and my directory here and then we're going to create a new folder here where we want to build the actual files so i'm just going to call this omsv tutorial so this is the directory where we're going to install and build opencv files with gpu support uh later on with cmake so i'm going to drag these files in here that we just extracted in the downloads directory so i have this opencv here and then the version i'm just going to drag them over so we have this one here and then we also need um the opencv contrib um folder here as well so i'm just going in here and then i'm going to just drag it over here to the right so i'm just going to take this one in here we both have opencv contrib here and almost to be here and then we actually need here before we're going to install the other things we also need to to create a folder here build files so this is the this is the this is the folder here where we're actually like going to have our build files after we've actually built v with tv support from scratch so now that we have opencv source file downloaded we need to install visual studio here as well so i'm just going into this site here and again i'll link to all the different kind of links here for the installation pages down in description so just go down there and click on so we're going to download the community version here which is just a free download of visual studio 2019 here i'm just going to hit the uh the download button here and it will start the download process here on my computer we can go down here to the file and like execute the installer here um and then we need to say yes and then this installer here comes up and we're just going through the pauses here click next and next until we get this sequence plus development environment that we need to download as well now we can see we get this uh development tool up here or like different kind of like workloads that we want to install when we're actually like downloading a studio so we need to go down here and specify that we need to that we want to install this desktop development here for cbs plus because we're going to use this here with cmake down here trying to like be able to build the source files from opencv support so i'm just going to check this out check this off here so we're actually like going to this here as well and we can see that the total space we cried here is is pretty much like seven and a half gigabyte and when we have chosen this desktop development with cbs plus here we can go down here and just install visual studio community 2018 here and then we don't need to do anything more here in visual studio code or we're going to use this to actually like be able to build the files uh with cmake so when we're building files here from from scratch with opencv and db4 we can both use it for sieverplus and also for python but if we want to use python we also need to specify the interpreter that we want to use and some of the library files from python as well we can use like a basic uh python installation on your own computer or we can use like uh anaconda to actually like be able on opencv with gpu support in python as well so i'm going to create another video into more depth and how we can set up opencv gpu support in python so make sure to to subscribe to the channel here and also hit the bell notification if you want to know like when i upload the video about how we can use opencv with gpu port in python because in this video here we're mainly going to focus on how we can use zipa plus and how we can set it up in visual studio code so the next thing we're going to download here is cmake which we're actually going to use to build our source files from omsv so we're just going to download these releases here and then we just take the latest one so in this case here we release a 3.2 0.2 and then we're just going down here and choosing the windows x64 installer and we're taking this msi file here which is just like an executable that will download cmake here on your computer so just hit the tab here and then you go into an installation process and just hit next next next until it is installed on your computer i've already installed it here on my computer so i can really show you the steps here so the last thing that we're going to download here is from nvidia so we're both going to cuda and we're going to use a cool dnn so first of all download cuda we just go in here and in this in this video here i'm going to use version 11.3 of cuda so just go down here and take this window here x x 6 86 here 64. and then we'll choose the version here of our windows operating system so in this example here i'm on 10 so i have windows 10 and then we just need to specify the installer type here and it doesn't really matter i'm just going to choose the local one here so we get an executable file and it will stall um cuda here locally on our computer so we just hit this one here and then we can just go down here for installer and click download here at this button and we just hit next next next in the installation process and it will stall cuda here on your computer so the last thing that we're going to download here is coo dnn so is like a gpu accelerated library of primitive for deep neural network so we're going to use this later on to actually be able to use uh the gpu with opensv to actually like be able to run the dnn modules and do uh deep learning neural networks inference and stuff like that but we're able to to be able to download this live here or program we need to first of all log into nvidia's developer website here so we can just create a an account like or a profile for free and you can just take the shorts away and then you can go in here we get the download links for coo dnn and then we need to set it up later on to actually like have a program then cmake will take take care of everything else after that so we go down and download coo dnn here version 8.2 so this is the one that i'm going to use because we can see that this version here is for cuda 11.x and in this example here i'm on on cuda 11.3 so i'm just going to choose this one here we hit download and then we just go down here and then specify the operating system that we're on so in this example here we're on on the library for win x 86 here in this example here so just hit this button here and it will download kudn library here for windows and it will just download this zip file here that we need to unzip and then we're going into the installation process after that so when we have this installed cooldown on our computer and we have downloaded this uh coo dnn uh library here as well then and extracted it and we're gonna like just go in and follow this guy here uh from the nvidia documentation here i'll just enter down the description here and you can go over the steps here one by one so it's really it's a really good guide here you just need to go into the different kind of path for cuda and also the coup dnn and then you need to copy some files back and forth between like uh de cuda and also the cuda computing toolkit over here to the right and then when you have done that you can go in that in edit some of the environment variables then we need to set up and when we have done that we have actually installed an independent program for uh code dnn and we can then use that later on in cmake to install and build the source files from opencv so we are now opening up cmake ui here where we're going to actually like build almost these source files first of all here we need to specify where the source files is so we're just going to browse the source files here we go into our directory where we downloaded and extracted all the opencv source files so in this example here i created this folder here called opencv tutorial i'll go into this one here and just choose where i have in where i have downloaded the opencv source files so i'm just going to select this folder here and then we also need to browse or like specify where we want to have directly stored the binaries that were built from the soils of opencv so i'm just going to browse the the the explorer here again and then we need to specify this build folder here which is just empty right now so i'm just going to delete what is already inside this folder here now so we just need to specify this build folder where all the binaries are going to be built from opencv here so we're going to select this folder here and hit the configuration bottom down here then we need to specify the visual studio that we just downloaded at the that at like the start of video then we also need to specify the architecture of our computer here in the example here i'm going to use x64 uh because this is what i'm i'm at right now and you're probably well if you're using windows and then we just hit finish here and it will just configure this uh offset up here so when the configuration is done we can see that we get these different kind of like options or like configurations that we can do up here above when we've actually like configured this setup here or like the configuration of uh building the source files here from mobius v so we can see that we get some configuration done here and if you want to use python as well then we can go up here and see that right now we actually like build the source files here for python as well so we're both going to be able to use it for pat and and cbs plus i'm going to create another video where i'm going more in depth how we can use it in in python as well but we can see here that it will both build it for python and opencv like c plus here as well and i'm just going to use like a base installation of python which is 3.8.10 but we'll build it for python as well if it is not building for python we can see up here at the top that the the obviously modules here that are unvariable if we have both java java and python 2 it will also specify python 3 here if it's not if it's not possible to build on your computer and if that's the case you need to upgrade numpy to actually like be able to build the source files for python as well but i'm going to create as i already said another video where i'm going more into details with with this setup process here so first of all here we need to do some different kind of configurations here before we can actually like generate the binaries that we're going to to build later on so here we're going to search for a different kind of things so if we want to download python we just go up here to python we need to specify the different kind of like include directories executables and stuff like that where we have our python executable file and so on but again i'm going over that in another video so i need to specify that with cuda here so we're going to width here and then we just need to go down here to width and then we have this underscore cuda so we need to have this value here checked out so we're actually using cooldown when we're building our opencv source files then we also need here the opencv underscore um underscore dnn so we just go down here and you just specify that we want to use opencv dnn cuda and we just uh build a build file here we also need to make sure that this mark here is checked out so we actually like building opencv with the dnn module here as well so we have done that we actually have everything set up here for cuda and we can also specify that we want to use pathmath for our opencv library here as well so we're just going to check this value here off as well and then we need to create the world files that we're going to use for actually like be able to uh load them in into into for example a visual studio where we're going to set them up later on in another video so we're going to have this build underscore opens to the underscore world and we're going to configure this here as well when we're going to build our our source files here with opencv then we need to go into the extras here we need to specify where our the module here is in the opencv control path so we just go over here to the values and then we need to specify in this ohms v underscore contribute then we need to pat to point to this uh to this modules here where we have all the different kind of like cuda algorithm arithmets a cuda fillers and stuff like that so we're just going to point to this modules uh library here in this uh omg underscore extra underscore modules path so we have done this here we actually have everything set up for now and we can just hit this configure configure button here again so now the configuration is done here once again and we only need to specify a couple more steps here before we can actually generate our binaries so if we go up here again we need to specify that we want to actually use a five math now so we're just going to have this past underscore math and we go down here to cuda and we want to specify this cuda underscore fast mass so we're actually using cuda to be able to do these operations uh way faster when we're specifying this value here another thing here that we're going to specify is the arc bin so we need to specify the version here of our gpu that we're currently running on and i'll link to this website here as well which is just the wikipedia website for cuda so in this example here i'm running on 6.1 here so we need to specify that in the arc bin directory so because i'm using a gtx 1060 gpu here in the computer but if you're using some other different kind of things like 2008 2000 and 2070 for example you need to specify this a 7.5 here instead of instead of 6.1 which i'm going to do in this example here so if we go down here we just need to delete all these things here and set except the version that we are running on now so now we have six point here which is the version that i'm running on and then we need to go into here and to the configuration and we need to specify that we only want to have it in release mode so we're just going to uh to to delete this debug mode here so now we have everything configured here and we can just hit configure one more time or we're going to generate the binaries here in cmake so the last configuration is now done here and we get as like a short sum over here the different kind of things so if we just scroll up a bit here we can see some different information here with the configuration for omcv and then the version we get some uh information about the cmec version here as well and some other kind of stuff here which is just not really uh relevant we can see like the version using cuda we have version 11.3 and cool dnn version that we're using is 8.2 so these are actually like the versions that we have downloaded so this is all good and we're using python here as well and we see that that installation is done to this user's underscore and then my directory obviously tutorial build and then into this installation path here that we're going to buy when we're actually like going to generate uh the build the binaries here and actually like building it and installing opencv here from the source files so now we have configured and all the configurations here is done we can just hit this generate button here and it will now generate all the different kind of files that we're going to use so now when it comes to configuration and the generation here is done and we have actually like built all the files to to our to our build directory we need to open up a command prompt here so i'm just going to go into open up command prompt then we have this here and we can just specify where we actually want to build and install opencv from scratch so first of all here we're going to use cma tracks like be able to build these things here so we have cmake build here and then we need to specify where we actually have this built up over here in our path so i'm just going to type this out here so i have it in my seat and then we're inside the users so users here and then inside of my directory and then inside the folder that we created so it will be mcv tutorial and then we also need to specify the build directory so where we actually like just have generated all the build files that we're going to build and install now with this command here with cmake here in our in our command prompt and then we're going to specify the target here as well that we're going to use so the target that we're going to use is installed we're going to install these binaries or like these from these build files here we're going to actually install the binaries and then we have done that we also need to specify the config which is release mode so we also have to specify the config i'm just going to do this here and i'm going to drop this this command here down in the description as well so you can just go down to the description copy paste the command and then just put it into the terminal here copy paste it into the terminal here just run the command and it will stall everything for you so we need to specify the reconfig here as well and we're running the config here in release mode so when we run this command here in the command prompt here we actually like we're actually installing and building opencv from scratch here so we can see that we get all of these different kind of things here it will take up to like one to two hours to actually be able to run all of these things here through and we see that we get a lot of different kind of like warnings here like errors but it doesn't really matter you'll get a lot of them though throughout this whole installation here but it doesn't really matter it will install them fine here in this directory that we specified so just need to let this here go for like one or two hours until it's done so when that process is done we actually have everything built uh from the opencv source files with gpu support so now we can just go into visual studio code here and i'm going to show you how we can set it up here in visual studio code and then run a short example on and we will get out some information about the gpu that we're currently running on right now so i'll just go up to the files here and we're going to create a new folder here so we're just going to have this folder here we're just going to owe a create folder here in this directory so i'm just going to call it uh opencv gpu test youtube so i'm just going to create this folder here we will select the folder open it up so we're going here we just open up the command palette here and we use the cma configuration so we just type in cma here and then we hit this config configure here we need to select the tools here or like architect that we're on but currently we are running on this architecture here so just choose this here in east mode so now we're actually going to create this c mag list file here we need to specify the name for the new project here that we that we're opening up so i'm just going to have opencv here dpu and and and then we have this test here and then we are running youtube here so this is the name of our file and we're going to create an executable in this example here for this project so we get up some lines of code here we have now actually like configured our cmake here so i'm just going to grab in and copy paste the the the setup for the cmake list for opencv here from my github because we already went over how to set this up here in another video so you can go check that out if you want to go more in details what these lines here does so we're just going to find the package here almost to be required we're going to include the directories here from opencv underscore include dears and we're just going to add the executable here which is the main uh just cb plus here so here we need to specify the project name here so we have another project name here with opencv opencv gpu test you so this is the project name here that i need to specify and i'm just going to copy paste this here uh down to the other ones here as well oh that was not the right one yes it was and here obviously we test so now we have actually set everything up we need to have these target linked libraries here as well so we're going to to actually specify where our link libraries are for opencv which is in this opencv on this list here so we can now see down here that we have actually set up this cmaglist file here it does everything for us configuration is done generation is done and the field files has been written to this directory down here in our project folder here so now we have actually linked and included our directories from opencv in in visual studio code and now we can just go in and use opencv with gpu support because that is why we have built with the files that we just learned that we're linking to in this specific cmake file here so now if we went to the main program here we just have like this short assembly here that i'm just going to copy paste as well and everything will be in my in my github on the description so i'll just kind of paste this in here we're including the iris stream library here for uh for cbs plus we also have from opencv here we're going to include dnn and the default one here for opencv then here we can actually like include opencv 2 core and then cuda so we're like using the tpu support for opencv in this uh in this include over here so down then we can go down here we're just using the namespaces here so we don't have to type everything out and then we actually have a function here from the cuda library up here that we specified where we can have this print cuda device information and then the device where we want to print the information from i'm only running on one gpu on my computer here so this will be the zeroth uh device here in this example so if you run a program now i hit control f5 here we will now actually run the program build the files here from this directory and then run it so we're going to debug console here we get some different kind of information about uh the device that we're now printing out so we can see how you are up to start here we have this cool device query runtime api version and we can see that the device count is one this example here so if you get the device count here as one and you're able to run this program here you have set everything up and you have built it the source file from opencv and cuda correctly so we get the device count here one so we're not right now we're running opencv with the gpu we can see that the device here is device zero and we can see that we have nvidia d4s gtx 1060 1060 and we have six gigabytes of ram here in rsq we can also see some different kind of information about our gpu and if we had several gpus we can actually just specify those as well but we can see both the clock speed some some different kind of like sizes like the the constant memory six gigabytes and stuff like that so we get all these different kind of information about our gpu because we're using opencv with gpu and we have set everything up we can see down here that we actually have the kuda driver version printed there as well so we have 11.3 and also decoded runtime version which is just the same and the number of devices here is one and then at the end here we're just printing out hello world which was the last line of code here in our program so now we have actually set everything up we have both installed all the different kind of things with cmag visual studio uh nvidia different kind of like cuda and coo dnn and then we actually just used cmake to build all the different kind of like binaries and set it up due to different kind of configurations then we went into visual studio here studio code here i showed you how we can set that up this cmake file here we have this short program here where we're just printing out the device information to be to like just uh to validate that our build file is working correctly and we're actually using opencv gpu when we're running this program here so thank you guys for watching this video here and remember to subscribe on the notification under the video here and also like this video here if you like the content and you want more in the future i'm currently just doing a computer vision tutorial where we're talking about like the basic stuff about computer vision and stuff like that and i'm also doing a deep learning tutorial where we're talking about the basic stuff about deep learning uh neural networks how we can create new networks from scratch training on a data set and then predictions on data that i hadn't seen before so computer vision and deep learning can be combined in a lot of different kind of ways and we can create some really nice applications very if you're interested in one of those tutorials i'll link to one of them up here or else i'll just see you next time guys bye for now
Info
Channel: Nicolai Nielsen
Views: 37,833
Rating: undefined out of 5
Keywords: opencv c++, c++ opencv, opencv python, python opencv, opencv gpu, opencv gpu c++, opencv gpu python, gpu opencv, opencv cuda, opencv cuda c++, cuda gpu c++, opencv source code, build opencv source files, cmake configuration, cmake opencv, cmake opencv c++, cmake opencv gpu, computer vision c++, opencv, NVIDIA, NVIDIA Cuda, NVIDIA cuDNN, The Coding Library, opencv nvidia, cuda opencv, cuda opencv c++, cuda c++, cuDNN, install opencv c++, build opencv c++, install opencv
Id: -GY2gT2umpk
Channel Id: undefined
Length: 26min 21sec (1581 seconds)
Published: Wed May 26 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.