AI on the Jetson Nano LESSON 18: Creating and Using Trackbars in OpenCV

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys this is polemic order from top tech boy comm and we are here today with lesson number 18 on our incredible new tutorial series where you are learning artificial intelligence on the Jetson nano I will need you to get out your most enormous mug of iced coffee and I will need you to get ready to rhumble no no we're not gonna rumble I shouldn't tease man because engineers are so such mild mannered people but if they ever start rumbling there's no stopping them so I shouldn't joke about that but what I will need you to do is I will need you to get out your Jetson nano gear Hey want to take a second like always and thank you guys who are helping me out over at patreon you're a huge encouragement to me when you decide to actually become a part of this channel and it helps me keep my gear up-to-date so I can continue to provide quality content for you but enough of this shameless self-promotion we are gonna learn some cool stuff today hey do you guys notice that like I made the little live window of the Jetson Nano there the little live window I made it smaller because I've been getting a lot of heat from you guys because I'll be topping something and it will go behind that window and then you really get to get mad at me but I really like it but I just made it smaller so can we reach the truce are you happy if it's smaller we'll try real hard not to get any of the program back behind it okay what are we going to learn today we are going to learn how to create and use track bars in OpenCV because to do artificial intelligence we have to lay the groundwork we have to lay the foundations and remember it's all about grabbing an image from the camera in displaying the image and sitting in that magic area between grabbing a frame and showing a frame and sitting there in Python and doing some mischief in there well in order to do our magic in there we've got to be able to interact in a tangible way with that window we learned last week the first thing which was really important which was was how to process mouse clicks so that we could get data and display things based on what the mouse was doing in the window and today is is very much related it's it has to do with track bars and so let's jump right in and let's see if we can get this thing going I'll need you to open up your visual studio okay and then I will need to get out of your way a little bit here all right that looks good okay we are operating in the folder called OpenCV and so we will go there and then we will come up to our main PI pro folder we will come over and we will click on the little plus icon and we will name this program CV 2 or I'm sorry our convention is open CV and I believe this will be program number seven and then we are going to call this track bar dot PI boom we're ready to code okay I remind you that we always start with the same base code the same foundation code that just runs out and operates the camera you should have that safe from earlier lessons but if you don't you can go to the most excellent ww2 PTT boy comm you can click the little search icon here and search on web camera or Raspberry Pi Cameron and something like that you'll get here pretty easily and then you see I have the code down here we are going to click on the two little page icons and then control V to grab that code then get this browser out of the way come over here and paste the code I should go ahead and change our base thing but you know one thing that we really like to do we like to move that window where it's not starting in random spots and so when we show the window we are going to do a quick CV to dot move window move window what in the window do we want to move we want to move our nano cam window and then what do we want to do we want to move it to I got to get outside of that string there okay we want to move it to zero comma zero all right let's fire this thing up just to make sure I didn't break something right mouse click run Python file in terminal and ahh okay I didn't break it I forgot that if you're using the Raspberry Pi camera we need to uncomment out these two lines okay if you are using a webcam you need to uncomment out this line and your webcam will probably be 0 if 0 doesn't work try 1 but the webcam should work on either 0 or 1 ok now let's see if we can fire this thing up we're in Python file in terminal there we go okay now let's queue out of this thing so we type Q and it kills it in a very graceful way and now we are ready to start doing some coding so we've got to create the track bar and we're going to do this after we create the camera but you got to create the track bar in a window and we don't have a window yet we create our window down here with this with this cv2 dot I am shown a no cam that's where the that's where the window is actually created but we need to go ahead and create that up here and so we are going to say C v2 dot named window and then what do we want to name our window we want to name it nano nano cam and this will be the same window down before but we're just introducing it up here so now we can work with it with the track bar before we get down into our while loop now let's create our first track bar it is C v2 dot create track bar and it guesses it that's always a good sign ok create track bar and now we got to give it some some numbers alright so I've got to give the track bar a name I'm going to call the name ex Val I guess I should say I'm going to name the track bar ex Val so ex val is a string x val is now the name of the track or that we are creating okay which window do we want the track bar to be created in we only have one window guys this is not rocket science you know Pam okay now we need to have a a starting value in an N value so we're gonna go from zero to 500 pixels okay or it's gonna be it's not pixels it's just going to slide from zero to 500 arbitrary numbers and then we have to have a callback function we are going to call the callback function nothing because here we really don't need to do anything in a function but we do have to create the function so we don't want it to do anything so we're just going to call it nothing hey a little thing about this parameter this track bar always goes from zero to some value the value that we're going is 500 this zero is not the start value it's the initial setting on the track bar so if I made this 25 okay the track bar is still going to go from zero to 500 but it's going to start at 25 okay think about that that's kind of just kind of need to understand that okay now if we're going to call nothing as our callback function we got to define it so we define what nothing and then : and now we got to define the nothing function what do we want the nothing function to do what do we want the nothing function to do absolutely nothing so we just give it a pass okay in this kind of like a little bit of nonsense here that we're having to do okay so now our track bar is created now we will come down here and we will get in our little magic room between reading the frame and showing the frame and that is where we do all of our craziness what do we want to do here we want to read that track bars so how would we do that well I can create a variable X Val now this is just a normal variable this isn't the same string X Val maybe I should call it something different but I'm just going to call it X Val so X val is equal to cv to dot get track bar position do you see it guessing that get track bar position and now we got to give it some parameters what track bar do we want well we want to get the only track bar we have which is ex Val okay and then which window is it in it's in nano can sometimes I feel like it should have already known that but anyway nonetheless we will do that so we want to go to the track bar ex Val it's in nano cam and now whatever that is it puts it in the variable X Val so let's just print X values to see if this darn thing is working okay X foul like that all right let's price right mouse click and let's run this sucker I have an uneasy feeling that I am NOT getting a happy little what did I do run Python file in terminal invalid syntax invalid syntax what did it not like about my nothing function define nothing you know th ing : pass that sure looks like a good colon to me what's wrong here Oh Y know what it is okay I got a pass at a parameter I'm sorry even though we're not doing anything yet I pass it a parameter so I'll just pass it X let's try it again that one scared me man I thought that should be working all right okay so look at this it goes from zero to 500 and then I'm printing out the value here and then when I slot it it changes boom I think we should do this more right the professional football players do it to celebrate their victories I think as engineers as we have these small victories we should do the double chest bump are you with me on that okay so do you see now I can slide the bar and then it goes into a variable that I can use in Python that is pretty cool okay let's go on let's do some more stuff here while we got this well if we created a track bar called X Val let's create another track bar what are we going to call it class class what are we going to call it we are going to call it Y Val but we'll just copy this one and paste it and change it to Y Val now I can come down here if I can read X Val what else can I do I can read Y Val and put it in the variable Y Val okay now let's just make sure this this works so I'm gonna print X valkaama Y Val alright right mouse click run Python file in terminal to track bars uh-huh to track bars uh-huh and look 25 25 is their initial value now just to show you you see I can go to 0 on Y okay so I can move these things around and then I've got these two variables that I can use in my program pretty cool huh what can we do with this can anybody see where I'm going with this I don't want to print them out anymore so I'm going to take that out what could I do hmm what could I do I could come down here and what I could do is I could create a circle see v2 dot can I create a circle cir c OE c v2 dot circle and now I've got to put it inside got to put it on some image what image do I want to put it on frame because that's the image that we read in right you should kind of be familiar with that we're going to put it into frame and then what we are going to do is we are going to give it a position well what position do we want to give it it's got to be a tuple so I open up another set of parentheses here how about how about x val comma y Val that would be pretty cool wouldn't it so now that's the position the radius is going to be five the radius of the circle is going to be five and now what we are going to do is give it a color 255 comma zero comma zero uh-huh and then we are going to make it a solid want a solid circle so we'll say minus one if you go like one two three it'll be kind of like the line width of the circle but if you give it a minus one it should make it solid okay let's see what happens here hold your breath the work what happened did I do that wrong one Python file in terminal ah okay look at that look at that little blue dot the little blue dot is where 25 25 uh-huh so now what happens if I slide this look at that that slides and this slide slides it in why and so let's say here I could put it there look at that pretty cool huh all right that's pretty cool now if I'm sliding across the page I probably should not set these things up as 500 and 500 x value display width right it should be kind of like the display width and I think it would be better if I change this to display width and then the Y value would be what this display height and so now my track bar sort of maps itself on to the dimensions of the of the window so let's run that again okay so now let's see if I go across it goes all the way down to the bottom and if I go across here it will go all the way I better move it up some or down some there you can see it see see I can put that little dot anywhere I want in the screen so if I wanted to try if I wanted to see like where this button is I could kind of bring this up and then bring this over now this you might rather do with a mouse click but believe me there are times that you will want to do these functions with track bars and they're coming up they're coming down the pike pretty darn quickly okay so that I think is pretty neat we have learned how to create a track bar okay now what I want you to do is I'm going to have to open a terminal and I'm gonna have to run a program here let's see LS I'm gonna go to change directory I should have already had this open I'm sorry I did not have this open change directory pipe row and then LS and change directory open or I'm sorry be patient with me on this okay don't hate me about this ok LS okay so I'm going to Python my track bars dot track bars dot I this is a different program this is your homework assignment okay guys this is your homework assignment how many track bars do I have for I make a little green rectangle if I move the xvalue what happens it moves the little green box up and down with Y value or it moves it right and left with X value but oh my what if I want to box my face that was crazy what if I want to box my face right there right there what's the problem the box is too small never fear I have another track bar called width and height and now I need to move it and now I need to move it and there you see I could capture my face now what you could do is you could go in there and you could actually capture that you can take that region of the image and do something with it and so you see I now can do this and so that is your homework assignment for next week what I need you to do is create a rectangle that you can control its position on the screen and you can control its size on the screen with a track bar and again these are things that you're going to need to be able to do in future lessons to go out and interact with that screen hey I had a lot of fun today man I am having a lot of fun as we're building this tool set we can do mount we can grab a frame we can show a frame in between grab and show we can draw circles we can draw lines we can put text on it we can process Mouse events we can go out into a color picker picker or now we can draw using draw using track bars and so I am actually pretty excited about this but your homework assignment for next week is to go ahead and do this and then I will show you next week how to do the program and then I think after that we're going to be getting really close to going in there and really start doing some of the image processing where we will then be getting to the point of really working on the algorithms and the techniques and the methods that will allow us to do things like recognize objects and track objects and so this has been 18 lessons and I appreciate you guys as patience but again what my goal is is for you to be able to go out and develop software on your own have an idea and then go out and pursue it on your own when I go through these videos where you know these tutorials where you're just like running someone's code and you have it's cool demo but you have no idea how to make your own code it's kind of like okay you're gonna spend your life running other people's code are you gonna start developing your own code you're that guy that's gonna develop your own code yes you are okay guys this I've had a lot of fun this is palma quarter from top tech boy comm I will talk to you guys later
Info
Channel: Paul McWhorter
Views: 7,662
Rating: undefined out of 5
Keywords: AI, Artificial Intelligence, Jetson Nano, Tutorial
Id: Cz56mNWYm6Y
Channel Id: undefined
Length: 19min 52sec (1192 seconds)
Published: Sat Dec 28 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.