AI for Everyone LESSON 5 HOMEWORK SOLUTION: Displaying Multiple OpenCV Video Windows

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys this is paul mcquarter with talktechboy.com and we're here today with the solution for the homework that i gave you in lesson number five what i'm going to need you to do is pour yourself a nice enormous mug of iced coffee that is straight up black coffee poured over ice no sugar no sweeteners none needed and as you're getting out your coffee as always i want to give a shout out to you guys who are helping me out over at patreon it is your support and your encouragement that keeps this great content coming you guys that are not helping out yet look down in the description there is a link over to my patreon account think about hopping on over there and hooking a brother up but enough of this shameless self promotion let's jump in and let's talk about what we are going to do today now last week we uh lesson number five i thought was really an epic lesson and that is where we learned how to install opencv and then launch a webcam and go out and grab a frame from the webcam and show the frame grab a frame show a frame grab a frame show frame we have a what it's called a movie and so we learned how to do that in opencv then what i did was i showed you a couple of commands to operate the camera operate the display window and even how to convert an image from a color movie to a black and white movie and then i do believe what your assignment was was to create four video windows where you had the color version of the image and then the black and white version of the image and then the color version of the image in the black and white version of the image to create four windows where you're showing two color images and two black and white images two color movies two black and white movies now how many of you guys were able to do it if you were able to do it leave a comment down below saying i am legend if you were not able to do it leave a comment that you folded up like a cheap walmart lawn chair are you legend or did you fold up like a cheap walmart lawn chair anyway what we are going to do is we are going to have me come over here and i'm going to fire up the most excellent visual studio code and we're going to code this thing up okay sometimes we don't want to just go back and redo the code that i already did in lesson number five and so i've posted that code for you at the most excellent www.toptechboy.com and if you go there and if you use this happy little search bar and this happy little search this site you can't see that can you because my big noggin's in your way i'm sorry so you're going to search here in this happy little search bar you are going to search on you're going to search on launch a windows web camera something like that search that and then you should come to this most excellent lesson and then you can see here that i have the 10 lines of code that you need in order to launch the webcam we're just going to start there rather than having to type those things in again and you can see you just hit the little double page emblem and then you can come over right mouse click and copy and now we will go back to the most excellent visual studio code and then we'll come up to our working folder which is python and then i'm going to click this little plus sign and then what am i going to do there i don't like the looks of that it was like it tried to put it inside of my virtual environment stop that okay let's try again i click down there i hit plus okay i think that it's just going to put it in the right place we'll pay attention to it look like it was putting it under the python videos okay so we're going to call this opencv dot py the dot py is kind of important now i'm going to come up here and i'm going to right mouse click and i am going to say paste and now we're square dab back right in the middle of where we were last week but just to be safe i am going to run this program to make sure that we didn't break anything with all of this crazy copying and pasting okay i don't know why on windows i have like a blindingly fast windows machine and i don't know why it takes so long i don't know why it takes so long to launch okay we put the cursor over the window hit q to quit out of this and that just confirms that we have launched a window or that we have launched the camera and are able to display a a video okay now what do we want we want to create four windows two black and white and to color so i hope please tell me that you were not that guy that went out and gray grabbed four frames okay grab four pictures to do this assignment how many images do we have to capture from the camera one okay it is the one image frame you don't have to go out and get four frames you can get one frame and you can show that one frame in multiple windows now this frame we're actually going to show in two windows and then we're going to create a gray frame and we're going to we're going to show that gray frame in two windows so let's go ahead now we've got frame from the camera now let's go back and we did this last week so you should know how to do this i'm going to create a gray and gray is going to be equal to cv2 dot cvt color and then what are we going to convert we're going to convert frame which right now is a bgr blue green red image we're going to convert frame using cv2 cv2 dot color underscore and then where are we going b g r to gray i glance over there to make sure that my head's not in your way but i think you can see that okay so now we have how many frames we have two frames we have a gray frame and we have a bgr frame let's go ahead and show those two frames and then i just want to make sure that i want to make sure that the program's working like what i thought and so we're showing already the color image frame and then what we're doing is we're moving frame to the zero zero position and what i've got to tell you is is that in this command it's sort of like x comma y x is this way and y is this way now positive x is like you would normally expect positive x to be but the thing that might be a little surprising is is that positive y is going down normally if you're doing real math y goes up but here y goes down and also the upper left of your screen the upper left of your screen is the point zero zero and so we are going and i'll kind of say this several times so that that so that you really understand it so we're taking this window my webcam we're taking that window and we're moving it to the zero zero position and so the zero zero position the first zero is x moves it all the way to the left and the second zero is y moves it all the way to the top so this puts the my webcam window in the upper left now let's go ahead and show our first gray window so i'm just going to snag these two lines of code and then just modify them so i'm going to control v to paste them and then i'm going to come over and be mindful of my tabbing now what we're going to do is we're going to we're going to say cv2 i am show not by webcam but we're going to say gray frame we're going to show my gray frame and then which image do we want to show there we are going to show gray can you guys see this okay i need to get halfway through the lesson but i'm going to make it a little bigger just to make sure that you can see this some of you guys might have a smaller screen so now we we're going to show the gray but i don't want to put the gray frame on top of the other frame so i need to move it where i need to move it over i need to move it to the right and so instead of 0 0 i'm going to move the first 0 the x value i'm going to move it over 640. why because our image or at least my image is about 640 wide and 480 tall and that's sort of like what my logitech is putting out you guys might have had to do it by trial and error but i knew that the logitech if you don't set parameters it's just going to give you a 640 by 480. 640 pixels wide 480 pixels tall so i want to move this over where it's not on top of the first one so i will move it over to the right by 640 that is an x value and we will run this program just with two windows just to make sure that everything is okay [Music] and i'm still i'm still perplexed why it takes so long you know i do a lot of this oh oh my goodness that does not look right what did we do wrong here okay what did we do wrong i'm gonna quit out of that uh yes i moved uh i did a move window i hope you guys were yelling at me i moved uh my webcam window instead of my grave frame and so the reason it was in a strange position is it was probably bouncing back and forth faster than we could see it so i'm going to move my gray frame okay so my webcam is moved to zero zero my gray frame is moved to 644.80 let's hope it worked that kind of scared me when i saw that because i thought something's wrong okay so something's wrong but i think we'll get it figured out here i think it's going to work right now we'll just enjoy a few sips of coffee here while this is okay boom who's your huckleberry yeah look at that i have a color image and i have a black and white image of the old top tech boy okay so we're going to quit out of that okay hopefully you guys had as much luck as i did now we need to create two more windows and so what i'm going to do is i'm going to undo that mistake i just made and now i'm going to create two more windows and move them two more times now what you've got to see is i don't need to create another frame i don't need to create another gray frame i'm just going to take this frame and show it in a different window and i'm going to take this frame and i'm going to show it in a different way though please tell me that you are not the guy that created another frame you know created another image two more images no all we need is two images and we display each one two times so we have a total of four windows but i'm going to snag those things and then i'm going to come here and i'm going to paste them and then i'm i didn't undo undo okay i'm going to get all four of those copy and then i'm going to come here i'm going to paste all right and now i need a third window so i'm going to call that my webcam 2 and then my webcam 2 and then my gray frame 2 and my gray frame 2. now we just got to adjust this webcam is still frame and then frame is still gray frame is still gray and so all those are good but now we've just got to adjust this now what did i want i wanted uh let's see i have my frame at 0 0 in the upper left so i want this one in the lower right okay i want this color frame in the lower right so i need to go to the right by how much i need to go to the right by 640 that's how wide my frame is and then i need to go down by how much i need to go down by 480 okay and then on the second gray one i just want it below the first one i want to come straight down with it and since i want to come straight down with it i don't change x at all x is going to be zero and then i am going to go uh yeah x is x is going to be zero and i'm going to come down by 480. okay and so you really need to look at this zero zero six forty zero six forty four eighty zero four eighty you've really gotta understand that because kind of the purpose of this homework is to get you acclimated to the screen to kind of know that x goes this way when you go towards the right that's moving in the positive x y goes this way as you move down that's moving in the positive y direction in this crazy scheme that opencv uses so now this should create four windows and they should sort of be color color black and white black and white in a pattern like that so let's try this have myself a little coffee [Music] and [Music] that tense moment as you're waiting for your program to run look at that boom look at that hello four of me okay and again my webcam is a little bit choppy because i am sucking all the resources out of my computer running my studio running my studio software so your webcam should be working a lot better than that but look at that we have four video screens okay guys i hope you had luck with this let me know if you had luck now i'm going to go ahead and give you a heads up of something that like one of the biggest things that you have to understand when you're doing these programs is to understand that some commands are given in x and y x is this way y is this way positive x is to the right positive y is down okay that's simple enough because from all of our math that we ever did it's always x and y x comma y x comes first y comes second the only different y is always up and down or the tradition is it's up and down and but here why positive y is down okay if that's all it was it'd be simple enough to remember but that's not all it is sometimes sometimes opencv wants x and y and sometimes it wants rows and columns now this is the tricky thing how do the rows go this is like row 0 row 1 row 2 row 3 row 4 row 5 row 6 row 7 row 8. rows go up and down columns come left and right okay rows are like y's and columns are like x's okay but but the convention when doing matrices when you're giving a coordinate in matrices is you give the row value comma the column value so if it wants the matrix notation of row column it is row comma column if it wants x and y it is x comma y what is the what is the confusing thing rows are like y and columns are like x so on the commands in opencv that want x and y you just put x comma y but in the c in the common in the in the parameters that want the matrix notation you put row comma column which is sort of like y comma x okay so one of the things we'll have to keep track of as we are doing these things one of the things that we're going to have to keep track of is we're going to have to keep track of the difference between the commands that want row comma column and the commands that want x comma y and usually it's really obvious when you get it wrong because your box is out of proportion or in a crazy place or something like that if that happens always check and see if you confused x comma y with row comma column okay so this has been a lot of fun what we're going to do next week this was a homework solution week so you don't have homework just play around with this a little bit more get comfortable with it and then in our next lesson what the next lesson is going to be is i'm going to help you out kind of being able to set your camera parameters and so when we just do it like i did it here what you end up doing is just launching the camera with the default uh settings and what i want to show you is how you can go in and kind of set things more specifically and i think maybe some of you guys struggled a little bit because you just fired it off with the default settings and your window was too big to really stack four windows together and so that would create a little bit of a problem it looked like a couple of you guys in the comments might have figured out that you could resize your window or that you could set the camera to a smaller size and those are the things that we're going to talk about next week as to how to start tweaking the parameters on your camera to get it to grab frames a little bit more specifically like what you would have okay guys you always want to have a secret words you can let me know if you've actually watched the end of the video and if you put the secret word in you might just get a little heart from me on your comment show you the love if you know what i mean so we will come down here and the secret word for today is vanilla plantation yes ladies and gentlemen in amongst my banana trees i have planted vanilla vines and you can see that this bad boy is crawling up that stem there and so my vanilla vines are about 20 feet and i am anxiously awaiting the day that we get a little bloom and start getting some vanilla beans on these things but i've been nursing these things for some quite some time the bananas are showing are doing just really exceptional producing a lot of bananas hope to one day in the not too distant future start getting some vanilla beans okay guys really appreciate you tuning in hopefully you're having as much fun taking these lessons as i'm having making them uh be sure to leave a thumbs up down below also leave a comment put your secret word in vanilla plantation make sure you subscribe to the channel when you do make sure you ring that bell so that you get notifications when the new videos come out again this is paul mcquarter from toptechboy.com i will talk to you guys later [Music]
Info
Channel: Paul McWhorter
Views: 4,478
Rating: undefined out of 5
Keywords:
Id: K_7TROgNFYA
Channel Id: undefined
Length: 19min 56sec (1196 seconds)
Published: Thu Aug 05 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.