AI on the Jetson Nano LESSON 13: Resizing Images in OpenCV

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys this is Palma quarter from top tech boy comm and we're here today with lesson number thirteen in our incredible new tutorial series where you are gonna learn artificial intelligence on the Jetson nano I will need you to pour yourself a nice big mug of iced coffee now we'll need you to get out your Jetson nano gear what you don't have your gear yet look down in the description down below and I have links to all of the identical hardware which I am using in this series if you're gonna play along at home it makes it a lot easier if we are working on identical hardware hey also want to give a shout-out to you guys who are helping me out over on patreon you guys are keeping my studio equipment up to date and you are keeping me in coffee beans really appreciate it you guys that are not helping me out yet think about looking down in the description there's a link over to my patreon account think about hooking a brother up put enough of this senseless advertising let's just get right in today's lesson and what we are going to be doing today is we are going to show you how to resize windows and resize images in OpenCV this is a little bit of a follow-on to our lesson last week where we showed you how to position your video windows in OpenCV and again as we are moving on we are going to be doing a lot of image manipulation and a lot of video analysis and a lot of video manipulation and so what you got to do is you've got to be able to keep your windows organized and we showed you last week how you can kind of stack them up and keep them where they're all neat so that every time you fire up the program all your windows are in the right spot well one of the things because we're going to be doing so much different things so many different things like like filtering or masking or manipulating the images a lot of times these things are sequential and you want to sort of see kind of at the effect of each each new process that you're doing on the image you would like to see them all stacked up well when you have a lot of them you would like to see these intermediate steps sort of in smaller windows and then finally when you come up to your end final product you want it to be a bigger window so you've got to not only be able to position the windows where you want them you need to be able to size them the way that you want them sized and so that's what we are going to be doing today so let me get out of your way and then let's come over and open up our visual code studio which we installed some number of lessons ago if you don't have this you can go back and install it and remember inside of our main our main folder was PI pro and then inside of PI pro we have this open CV and we've done now open CV one open CV too and now we will do open CV 3 so I need you to click on your open CV folder come up here to the little icon under PI Pro which says create a new create a new file and what are we going to call this well this will be open CV 3 for lesson number 3 and then we're gonna say resize windows dot py ok boom there we are now you remember a few lessons ago we started with the code that's sort of that we're going to be using as the starting point for all of our programs it's the code that fires up your camera and it will fire up either a Raspberry Pi camera or a webcam so we need to go over to the most excellent ww top tech boy calm and grab that piece of code if you want a link directly to the page that has the code on it look in the description down below I give you a link where you can come right with 1-click to this lesson and then we want to come down here and we want to click on this little two pages these little two pages on top of each other right mouse clicking copy then we can get this out of the way and then come back to our lesson three and we will paste the code in there and just for good measure let's run it to make sure that it is in fact working so run Python file at terminal and how do you like that oh I know you got to decide what you're going to run if you are running the PI cam you need to uncomment these two lines okay and then it should run so I will say run Python file in terminal boom and there it is back in random position which we fixed in the last lesson by using the move window command but you can see that we did fire off the PI cam or similarly we could instead of that if I commented those back out those two back out we could uncomment out this one which is for the webcam and your webcam if it's the only camera on your system it will probably be camera zero me since I already have a different camera on there my webcam should be cam one so let's run Python file in terminal boom there it is again in a strange location but there it is okay cute all right so I will I kind of prefer playing with the Raspberry Pi camera so I will uncomment out the Raspberry Pi camera and I will comment out the webcam so we should be ready to go here okay so now what is the goal of this lesson the goal of this lesson is again to keep our windows organized our video windows organized and when we're going to be doing a lot of video processing what we'll need is we'll need a lot of small or intermediate windows which means we need to be able to have a way of making the windows smaller and guys this is kind of the way I do it I don't try to resize the windows so I don't like create a window and then resize the window what I like to do is I like to resize the image and then work with a smaller image and and just show that show that smaller image and so let me show you what I'm talking about here so we can come over here and let's see what we are doing we fired our camera up up here and now what I do is I read a frame the camera is called cam and so I read a frame with the command cam dot read and then I show it so I read it I show it I read it I show it okay and then we saw that it was in a crazy location so let's go ahead and make sure that it's in a good location so we will say C V 2 dot move window which we learned how to do last time and I'm gonna call it let's see this is going to be this will be our nano cam and we where are we going to move it well I'm gonna move it over to the right I'm going to move it to the right about 700 and then keep it in Y about the same all right like that and then the next thing I am going to do is I'm going to create a new image and I'm going to call that gray and gray is going to be C V 2 dot convert color remember C V T color I believe we learned that last week so that C v2 dot C V T color and then what are we going to convert we are going to convert to the frame frame and then how are we going to convert it C V to C V to dot all uppercase e olor and then I am gonna get further out of your way there we go see v2 dot color and then underscore underscore and then it is going to be blue green red BG are all uppercase BG are to pray and you can see that it finds it down here right there and so I can just click on that to finish it out for me and then close that you can see that nice and nice and fine so gray is equal to C V to CVT color and then what we going to convert frame how are we going to do it we're gonna go color the blue green red to grey so now I should have two full-size images one is called frame and the other is called gray and the gray is great okay so now I'm not going to show the gray I'm just going to kind of hang on to it for later all right and so now what I want to do is I want to come in and show you how to resize these images and so I will come back over here and what are we going to do we're going to make smaller versions of these so I'm going to say I want a let me start with my frame I want my frame my main image and I want a small version of it and how do I do that see v2 dot re-size C v2 dot resize and it recognizes that and so that's good and I'm not resizing a women window I'm resizing an image so I just say resize what do I want to resize frame okay and then what do I want to make it I want to make it 320 by 240 so that's kind of about half as big it's what we started out right we're at 640 480 on the main image and now I'm coming down here and I am going to be where was that I'm going to be 320 by 240 so now I have a small version of frame let me also make a gray small and similarly see v2 dot resize and then what I'm going to do is I am going to resize gray and then how am I going to resize it 322 240 just like the other one all right that looks pretty good I really think that that looks pretty good so now I've got two I've got two smaller - smaller images well if I'm going to do those two smaller images what I better do is I better tell it where want them so I better give it a good location so I'm gonna say cv2 dot move window and then what window do I want to move what window do I want to move well I am going to have a I'm going to have a new window which I'm going to call the W for black and white and where am I going to want BW I'm going to want BW at 0 and 265 0 comma 265 and so that's gonna be a little black and white window and it's not going to be up in the corner it's gonna be up in the corner and over to know that will be down to 65 ok I get my left and right and up and down got confused sometimes we're also going to do see v2 dot move window and I haven't created these windows yet but I will just in a second I'm going to get their position first and so this one is going to be we'll call it we'll call it nano small because our original was nano cam and so we're gonna call it nanos small and then this one is going to be kind of down and over and so let's see where am I gonna know I'm going to put this up in the corner I'll put this one up in the corner right because that other one was over that other one was that other one was down by 265 and so this one will be up in the corner so now I have three images done ok now I need to show those two things that I just set up so I'll say C v2 dot IM show and what i will show is i will show the black and white and then what i will want to do is what do I want in there well I want gray small does that make sense I want grace small okay and then the other one that I will have is see the two dot I am show and what I will want there is I will want nano small and this is going to be my small version of that frame so this is going to be frame small like that okay so if I am NOT crazy which I might be this should give me three windows it should give me my main large window and then it should give me a small color window and then it should give me a small black and white window okay let's try this and see what kind of what kind of train wreck we get here run Python file in terminal hey boom look at that okay see see now what are we doing we are not just moving windows we are resizing the images and so if this was image processing going on over yeah over there in the corner then I've got two smaller windows that I could see kind of the progression of my image processing okay so let's go ahead and let's quit this and then let's make a couple more windows just for a good practice so I've got those four windows and so now what I'm going to do is let's just make a couple more windows based on the images that we already have so I'm going to say CV to dot move Windows so I'm going to make a new window and this is going to be this is going to be black and white window - okay black and white window - and then where am I going to put it black and white window - I'm going to move over by 385 and then I'm going to make it to 65 down okay so this I think would be the bottom corner window and then I'm going to do CV to move window and this will be a new window you could do this with new images but I'm just reusing the frame so that I don't have to create new images here but I think you get the gist of it so then this is going to be nano cam to nano cam - okay and I need to put the quotes around that I hope this auto-filling business isn't getting in your way nano cam - like that and then where is that going to go well that is going to go at 0 left and right no that's going to go that's going to go 385 to the right 385 to the right and 0 okay let's look at that so this one is going to be down in the corner and then this one's going to be that second column on the top I do believe if I'm not mistaken but let's run this and then I probably have to do those AIIMS shows there ok so then I will do CVE - to show those windows imshow and what do I want to show I want to show black and white - what do I want to show in black and white - I want to show gray small ok and then see the 2 dot I am show and then what I want to do is I want to show I want to do I want to go into I want to go nano I want to yeah okay so I am doing my nano cam to here I'm gonna I am show my nano cam I called that nano small didn't I you know cam - okay I called that nano cam - okay and then what do I want to show in nano cam - frame small okay let's stop and think about this so I've got gray small and I've got frame small I've got grey small I got frame small I've got black and white - and nano cam - I've got black and white - and I got nano cam - I think that's right so let's run this thing run Python file boom look at that five windows uh-huh so you see how now I've got kind of like my main final product which we would think large and then you could think of these four images as intermediate images leading to this one and so that is pretty cool so let's kill that with a Q and then let me come back up here and what if we started what if we started larger with this thing what if we started at the display of our main image what if we made it 960 and then what if we made it 720 so our final product could be bigger run Python file in terminal boom look at that so you see there I would have room for even more rows there to the left of the image of you know kind of intermediate images and look one two three four five that's really good I'm not seeing any latency there okay that is really good so I am going to quit I hope I'm going to quit there it goes okay so now what I want to do is I just really quickly want to show you how you would do this if you were using the webcam and so what I'm gonna do is I'm gonna comment out these two okay and the thing is if we use the webcam okay and just still call it Kim if I use the webcam the problem is these two parameters are not used in webcam the webcam it just fires it with pointing at it and you don't have the ability to build that string where you put parameters in so in that case you have to come afterwards and set those parameters so I'm gonna say cam dot set and then what am I gonna set C V 2 dot okay now watch the CA P okay underscore proportion okay underscore frame frame and then I'm gonna go ahead and I am going to set the frame width so I will choose the width 1 and then comma what do I want well I'll just set it to display width so right now I'm putting that parameter in from the top of the program okay and I think the easiest thing to do would be to copy this and then the easiest thing to do would be paste it and here in this case we're going to do display height the display height and then this one would be hei ght okay so this should give me big on the webcam and then it should give me 6 small ones so we've turned the webcam on so let's try that run Python file in terminal what does that know oh all caps man were you guys yelling at me they're all caps H e IG HT let's try that run Python file in terminal boom come in from the webcam come in from the webcam five images one two three four five one two three four five okay five images from the webcam just changing a couple of lines of code just changing a couple of lines of code all right let me quit out of that and this is looking really really good let me show you what would happen if we did not do those cam sets after setting up the webcam I think the default is just 460 is 640 by 480 so let's look at that and see what happens yeah you see it looks like that the webcam if you don't set asides is going to come up 640 by 480 and that that is what you would get okay so guys this is this is really really important so you see how we're able to make smaller windows and look at a bunch of different windows and then have a bigger window that we can then do what we want to with and so what I like to do is I like to resize the image and show the resized image and not try to resize the window what we might do is we might leave the window big and then we might run over and make a smaller version of it to display and we might be doing a lot of our image processing on big windows but then creating little thumbnails for us to look at over at the side does this make sense are you guys kind of seeing what we're trying to do so what I want you to do for homework is I want you to try to create more windows and get them positioned and see if you can get in there and kind of tile a bunch of small windows and then have your your main window be larger where you actually want to be doing your work all right palma quarter from top tech boy comm would really appreciate it if you guys would give me a thumbs up it helps me if you give me a thumbs up if you like the channel subscribe to it when you subscribe be sure to ring the bell be sure to click that little Bell because then you'll get notifications when I have new videos coming out and again want to give a shout out and really appreciate you guys who are helping me out on patreon okay this is poem quarter from top tech boy comm I will talk to you guys next week
Info
Channel: Paul McWhorter
Views: 9,652
Rating: undefined out of 5
Keywords: Jetson Nano, AI, OpenCV, Tutorial, Artificial Intelligence
Id: nQNXWFR6Sm0
Channel Id: undefined
Length: 23min 54sec (1434 seconds)
Published: Sat Nov 23 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.