OpenCV with CUDA in Python on Jetson

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
after spending hours Building open CV with Cuda support on a Jetson some people get a surprise when the new version does not show up after importing CV2 we launch python import CV2 and then we print out the version and it's the original version on this episode we are going to go over how to fix that first we will build open CV with Cuda support on a Jetson Nano then we will go over why this Abomination happens finally we will fix it after that we will celebrate with a demo showing Cuda goodness Jetson Community member Michael degon has written a script to build and install open CV with Cuda support on Jetson make sure to Star his repository on the mdan account on GitHub there is a repository named Nano build open CV let's get clone the repository and switch over to that repository's directory let's open up jtop and go over to the info pane the open CV version is 4.1.1 with Al Cuda and for our build we need to know the cud DNN version which is 8.2 let's quit out of this let's edit the build script we can see that the install directory will be/ user SL looc scrolling down we see the install dependencies we use appt to install them let's scroll down a little more here are the build flags we are going to use to build open CV we need to make a couple of changes the Cuda architecture 8.7 is for the Jetson Orin the Jetson Nano doesn't know what to do with that let's get rid of it and jtop told us that we need to use cudnn version 8.2 so let's change that let's make sure we saved the file then close up the editor here's the changes we made now we are ready to start our build we are going to build version 4.8.0 password and We're Off to the Races this build took about 7 hours and 10 minutes seven hours later password we're getting ready to install everything and then we're asked if we want to remove the temporary build files I always say no I always save the temp files in case I need them later the build files are in the /tmp directory I'll just copy them over to the home directory for the time being note that the TMP directory means temporary your build files may disappear if you run out of drive space or if you reboot the machine let's see what we have here let's run jtop let's switch over to the info pane we see that open CV version 4.8.0 is installed with Cuda let's get out of this open CV has a command line utility that we can use to check the version version 4.8.0 let's fire up Python 3 we import open CV by importing CV2 let's print out the the open CV version and it's 4.1.1 what what the we are back where we started we know that jtop and the command line know about version 4.8 but python does not we use the witch command to determine the location of the open CV version program I'll get you my pretty and your little dog too not that kind of witch it's in sluser lo/ bin let's switch over to/ user we are in a system area let's use sudu password now we see that there are two versions when we run the version in/ user bin we get 4.1.1 if we run the version in local bin we get 4.8.0 this is the same version we are running from the command line now you are asking how does the command line know which version to run the path environment variable is a list of directories that the shell automatically searches through to locate executable programs and scripts let's take a look at the path environment variable here are the directories and the order that they are searched we can see that user local bin is searched before user bin therefore we run the open CV version 4.8 now why doesn't python do this let me tell you the [Music] story no not that story python has a similar mechanism for looking for modules but is different than the path environment variable let's import the CIS module and then print the path variable now we need to figure out where our new version of open CV is stored we can get that from open cvore version with the minus V flag you can see that we are installing it into sluser looc and here's the Python 3 install path when we combine the two we get this for its location there are different ways to tell python about this one way is to set the python path environment variable then the next time you start python that directory will be in your path list let's make it a little more permanent we'll add it to the bashrc file we want to add the directory that holds the CB2 module let's make sure we save it the moment of truth let's open up a new terminal we fire up python import CV2 print the version 4.8.0 I beat it at its own game it's demo time let's install our demo we need to install get large file system that will help us download the models on the open CV account on GitHub there is a repository named open cvore zoo let's clone the repository and then switch over to that repository's directory then we grab the models then we switch over to the demo directory which is modelsface detection yunet for the demo I made the camera window a little bit larger I've modified demo. piy a little bit let's take a look at some of our options here we can use the default open CV implementation on CPU or Kuda plus a GPU or Cuda plus GPU and that's in floating Point 16 mode Let's try it with the CPU first ha you didn't expect that did you it's a face detection algorithm and we can see that we get between 8 to 12 frames a second here which is pretty good let's just run on the CPU let's take a look at jtop here we can see that the G CPU isn't being utilized very much let's try it out with open zv Cuda change this to one there we go you can see the frame rate about doubles up to 20 to 22 somewhere in there you get a pretty good performance boost just by adding Cuda here you can see that there's not a whole lot of GPU usage when I'm just sitting still when there's movement in the frame you can see that the GPU usage is quite dramatically increasing that's kind of interesting and then when I settle back down GPU usage goes down and let's try the floating Point 16 version change that to two oh that went into dog mode that's three frames a second and the GPU is just cranking on it it can't believe it you can see that it's much happier running in lower Precision I hope this explanation helped you thanks for watching
Info
Channel: JetsonHacks
Views: 8,355
Rating: undefined out of 5
Keywords: tutorial, jetson orin, jetson agx orin, jetson orin nx, jetson orin nano, jetson agx xavier, jetson xavier nx, jetson nano, jetson tx2, jetson developer kit, jetson development kit, face detection, face detection demo, face detect, GPU, CUDA, opencv, open cv, demo, install, ubuntu, jetson linux, l4t
Id: BCNnqTFi-Gs
Channel Id: undefined
Length: 8min 38sec (518 seconds)
Published: Tue Nov 07 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.