AI for Everyone LESSON 12: Understanding the HSV Color Space

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys this is paul mcquarter with toptechboy.com and we're here today with episode number 12. in our incredible new tutorial series where you are going to learn artificial intelligence or you're going to die trying what i'm going to need you to do is pour yourself a nice strong glass of iced coffee that would be straight up black coffee poured over ice no sugar no sweeteners none needed and as you're pouring 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 take a 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 this shameless self-promotion let's jump in and let's talk about what i am going to teach you today and what we're going to do is we're going to start trying to understand colors a little bit better and understanding how to analyze a scene in terms of the colors that are within that scene now up until this point in our lessons we've gotten very familiar with opencv and in particular we've gotten very familiar with how to think of a picture or a frame from a video is just any other data set it is a two-dimensional array it has rows it has columns and at the intersection of rows and columns there is a pixel and when you stack all those picture pixels together you get a picture and you've gotten familiar with how you can go out and grab a part of that picture and create a region of interest you can go in and manipulate the data to do certain things to that frame so you've sort of learned to find your way around an image or a picture as a data set now the reason you would want to go in and grab a frame or grab a region of interest from a frame is maybe there's something interesting in that region of interest maybe it's something that you would like to track or that you would like to follow and that when you start thinking of it that way you're really starting to kind of get into the early stages of artificial intelligence and so what would be the easiest thing in an image to try to track on well the easiest thing to kind of introduce this concept is to track on color so let's say that you had a uniquely colored object in your frame and you zoom in on it you create a region of interest around it and then you track based on that color so imagine i put a bright red dot on my finger and then move my finger around you could track my finger based on the fact that i had a bright red dot on it so the easiest way that we can begin to work our way into artificial intelligence is to try to track something based on color and so to do that i'm going to jump in and we're going to be working in the color space that we've gotten familiar with which is the red green blue color space or for the case of open cv blue green red but where you're mixing blue and green and red to get different colors and then i'm going to kind of show you what the challenge is of working in that color space and so let's go ahead and start by opening up our most excellent and i should probably get out of your way here sorry do a little windows management here i need to get out of your way and then i need to move over where you can see my screen and then what i will need you to do is open up the most excellent visual studio code and then we're going to start a new program so we are going to come over here and we are going to create our new program which i believe we are going to call this time open cv dash 15 dot p y and the dot p y is pretty important and boom a fresh new python program just waiting to be written and what i'm also going to do is as always we don't really want to start all the way from scratch and go in and just start you know writing the the code to grab and show the frame so let's go ahead and start with our base program you guys probably already have it if you've been watching this series of lessons but for those of you who might just be joining us in the middle i'll need you to go to the most excellent www.toptechboy.com you can come over here to this happy little search icon and you can search on the lesson called faster launch of webcam you'll come to this lesson and then you've got some code down here click on the two little page icons right mouse click and copy and then come over here to your python program right mouse click and paste and then we want to run this just to make sure that it still runs and so i click here and it crashes and when i look at this it says that it's not grabbing the frame well i believe for some reason on my setup it's decided that the webcam is camera zero instead of camera one and perhaps i've got several different usb devices and it's just loading them into a different direction but we've talked about this before your webcam is probably either webcam zero or webcam one here in line number five of the code let me get that out of your way let me get this a little bit bigger so you can see it i think you can see that a little bit better so i've changed that to camera 0 and let's see if it works now boom there it is we can copy and paste shazam okay but let's go ahead and quit out of this and now let's go in and let's start thinking about color okay and uh what we're going to do is we're going to go out and we're going to snag a color from our frame and we're going to display that color and then we're going to kind of look at what the data looks like for different colors different real colors that come from our frame so we're going to write a little piece of code that's going to go out and based on a what based on a mouse click where we click the mouse it's going to go out and it's going to grab that color wherever we click the mouse so if we are going to do that what do we need to do well we are going to need to listen for a mouse click so we're going to have to set up a mouse click so i'm going to say cv2 and i do this right before the while loop because that's just kind of a convenient place to do it so i'm going to listen for a mouse click cv2 dot set mouse callback set mouse callback and then which window do i want to listen on for a click on which window well we have my web cam and why that because that is the window that we're going to use down here in the program and then i need to tell it what do i do if uh if there's a mouse click will i go to the function mouse click like that okay so if there's a click it's going to run up to the function mouse click now there's a couple of problems here one i've not defined the function mouse click which we'll do in just a second and the second thing is as i go through the program when i get to this line of code at this point there is not a window called my webcam so i better create that before this line of code so that it doesn't crash and so i'm just going to do a cv2 dot named window like this and if you guys have been following these lessons this should be very familiar to you i'm going to call it my myspace web cam okay like that now you can call it whatever you want to call it but whatever you create here needs to be what you listen for a mouse click here on and then it also needs to be what you're using down here so everybody is kind of talking to or listening to the same window so at this point it's now the program's going to be listening or paying attention for a mouse click in this window called my webcam now the problem is now is is that we say when you get a click you run up to the function mouse click and we have not defined that function yet so we're going to come up here and we're going to find that define that so i'm going to define the function and it's going to be the function mouse click and then when mouse click is called from the set mask mouse callback uh line of code below it's going to pass parameters into it so we've got to grab those parameters the first thing it's going to pass the event what actually happened to the mouse was that the wheel the button down button up whatever it's going to pass it a code to tell it what actually happened with the mouse and then it's going to pass x position of the mouse and it's going to pass a y position of the mouse when that mouse event occurred now it's going to pass some other stuff that we're not going to use but i'm just going to put in some dummy variables because you've got to catch them whether you're going to use them again so i'm going to pass i'm going to have the parameter flag and then params and we're not going to use flags or params but i got to catch them because that callback is throwing them at me and so now this is going to be my function all right what do i want to do when the mouse button is cl is clicked well i want to look and see if it is the left mouse button down because when the left mouse button goes down i want to grab that color when the left mouse button goes down i want to grab the color that is underneath the cursor wherever it is okay so what will i need to do well i need to say if the event that just happened if it's equal equal to cv2 dot event underscore left button down okay that is my action that is what i am interested in i am interested in left button down okay now if left button down happens i want to just print the event i like to print it just to make sure that i kind of see that i entered this function that i entered this if statement so i want to print the event and then i need to make that event available down in the rest of the program and so i need to set a new variable evt equal to event and then if evt is going to be available to the rest of the program up here i need to make it a what a global variable because the things that are just sitting up here in this function the the normally the variables that are up here in this function the rest of the program doesn't know about it so if i want everyone to know what the evt is i need to make evt a global variable like that does that make sense i hope it does so i make that a very i make that a global variable and then also what else do i want well down in the main program if i click here i click here i click here i need to know where the cursor was when i clicked so that i can watch so that i can grab that color that is at that point so i will also need to have a global and i'll just call it since i already use the variables x plus and y pos i'll call these global ones x the x vowel and uh glow ball y val and that way the main program will know not just that a mouse event occurred but what the x value and y value was of where the cursor was when that click happened i hope this is making sense you guys should understand this at this point okay so i also need to set those and so if you actually click the left button down then what i need to do is i need to say that the x val is equal to x plus so it's sort of like the global variable is equal to the local variable so then the world will know what it is and then i'll say y y val is equal to what y position like that so now when that left mouse button goes down it's going to come into this into this mouse click function and then it's going to come into this if statement and then the whole world will know that the event happened it will know what the x value was of the cursor and the y value was of the cursor when that event happened does that make sense i hope it does okay then also i also like to just kind of be able to kill things and so i'm going to say if event is equal to equal to cv2 dot event and then i want the right button i want the right button up let's say right button up so if i click on the right button and then let it up then i can do other things like kill the window or do whatever something like that so i just want to keep track of that and i do need a colon here and then what i'll just say is e v t is equal to event and then i might need to know what that is so i'll just go ahead and print event just so i can look at it okay so now this lets the world know this lets the whole program know that a button was pressed and where the cursor was when that button was pressed okay now a couple of things that i will need to do a couple of little bookkeeping things remember that the main program that when it's running it's not if i haven't clicked the button yet there's no value for evt or xpos or ypos so i better give those some value just so the program doesn't crash in the loop when i'm doing something with those variables if the button has not been pressed yet so i'll just come in here and i will say i will say e v t equals 0 i'll say x x val is equal to 0 and i'll say y val is equal to zero just to seed those things so the program won't crash if if it runs into them down in the main loop okay now what i'm going to do is i'm going to write a little program that when you click on when you click on your mainframe it will tell you what the color was that you clicked on so what i'm going to need to do now is i'm going to need to come down here inside of i'm going to need to come down here inside of the while loop i read the frame and then i need to see has the has the button been pressed has the mouse been clicked so i'm going to say if and then what if evt equal equal 1 that is one is the code for that left button down okay so this is saying if the left mouse button has been pressed down then what do i want to do well i want to create a new array and i'm going to it's sort of like i'm going to make my own little region of interest if you will so i'm going to say that x is going to be equal to i'm going to create a blank picture i'm going to create a blank picture how do i do that i do that with the np.0 function remember the numpy zeros function we did this a few lessons ago well if i'm going to use numpy i better import it up here so i better come up here and say import numpy as np because i need to create a blank little window so now i can do that so i can say that this new data array this new picture if you will x that i'm going to call it is equal to np dot zeros what does that mean that means that i'm going to create an array i'm just going to fill it with zeros okay but now i've got to kind of tell it how big i want it to be okay well i want it to be 250 pixels rows i want 250 rows i want 250 columns and then at the intersection of each row in each column i want three numbers because i want it to be a color picture so i need a blue a green and a red so the third dimension is going to be three so i'll have a spot for blue and green and red now i've got to tell numpy i've got to tell our friend np 0s what type of number to put in there so yeah there's 250 rows 250 columns and at each position there's going to be three numbers but what kind of numbers do i want well i got to tell it the d type and the d type that i want is i want an 8 bit unsigned int and so this is going to be np for numpy dot u i n t for unsigned int and then eight bits and so that just will give me it's kind of like declaring a variable i want all those zeroes to be an unsigned integer that's eight bits long and so i think we did this before and so this should not be a surprise to you so x is equal to numpy zeros and then it is going to be numpy unsigned int 8 and so now i've created an array and let's just go ahead and just make sure that this works so far so what i'm going to do is i'm going to go ahead and say cv2 dot i am show i like to run my code a lot just so i don't put in a thousand errors and it's harder to debug so let's go ahead and show this and then uh i'm going to just go ahead and i think i will call this window color picker because i'm picking a color and then what do i want to show i want to show x and then after i show it what do i want to do cv2 dot cv2 dot move window and i don't want it like behind the frame and so what do i want to move i want to move my window color picker that i just made okay and then where do i want to move it well i want to move it over by the width of the mainframe and so i'm going to move it over by width move it over by width and then i'm going to go down by zero okay and this should give me a what okay i put zeros in that whole array this should just give me a black frame okay let's see if it works or if it's just gonna crash on me okay now i've got my frame that's expected why is there no little black window well there's no little black windows because i haven't clicked and so let me just click boom look at that so i've got my little i've got i've got my mouse working anyway and the mouse is then firing off that little completely black window okay but do i want it to be completely black i really don't want it to be completely black i want it to be the color of wherever the cursor was when i clicked it so i better run out and i better i better run out and i better grab that color okay and so what i could say is what i think i could say is i could say that i'll say clr like that color is going to be equal to it's going to be equal to the frame okay because i want to know where i clicked on the frame so it's going to be the color is going to be equal to frame and then which remember frame it's it's when we're dealing with data sets on the frame it is row comma column so the first number is row okay the first number is row and what is the index then that i want row is what it's y value okay it's y val okay row is y val and so i've got row y val and then co and then column what that would become column x val so i go to the row y val and i go to the column x val and that is where my that is where my cursor was and now what do i want to do well that data point that i grabbed that's the what that's the color so then let's print clr like that and let's make sure that i'm thinking of this data right so down here now next time down here in the bottom and i need to move this up a little bit to make sure that you can see that that looks good okay now let's run this and see if we can get a color good news it ran okay now can you see i have my cursor over the green so when i click on that green when i click on that green then i should have the little window pop up that's black and then it should print down below what the color is okay there it goes now one thing i don't like very much is it's printing it every time and so before i do anything else like let me quit why because when i clicked it the first time it set the evt to zero it reset the evt to one and so even though i'm not still clicking every time through this loop evt is still equal to one so after i grab the color i want to go ahead and set evt equal to zero so it doesn't just keep printing that number it doesn't keep going and grabbing it it grabs it when i click it and it grabs it once then it doesn't do it again until i click again does that make sense okay this time it should print one time okay there it is that looks good so now i'm going to click okay boom i get my little window i get my little window over there okay and then i see what that color is that color is 117 29 and 50. okay 127 117 29 and 50. okay now why do we not like that so much if you look back here this is green this is green and these three numbers are blue green red but you see what the i sees as green what the eye sees is green the computer says well yeah that's green but there's a whole lot of blue in there okay so you see this is this is kind of the problem that we have here if i wanted to track on green i think green is green and when i look at this background i think it's green okay but treating it as data the computer says yeah it's green but it's got a lot of blue in it well if i wanted to reach out and track on green then what range would i say like what ranges of green would be green and what ranges of blue would also be green and so this creates an almost impossible thing to track on but we'll get back to that in a minute let's see if i can uh i don't know if i don't think this will actually work but what i want to do is i want to come in and i want to say that x okay i want to now make my i want to make my x array i want to make it that color so i'm going to say x is equal to but which x well x the colon will give me all roll rows and then the colon again will give me all columns right if i put something to the left of the first colon that will be the start row if i put something to the right of the first colon that will give me the end row the start row in row but if i just put the colon it's all rows comma colon is all columns and you guys should know that from our earlier lessons okay so i want to see if i can set that to and just set that equal to clr now i don't know if this is going to work because it might want commas in there but let's just see if this works so x is equal to that and so now i've given everything a color but i just really think it might want okay there's that now let's see what happens when i click okay yeah that didn't work so let's see here so i say x is equal to clr why did that print it let's try that again i thought that was giving us a value let me see if that works okay i'm going to come over here and click ok boom it is working it's just the thing is glitching because my uh my studio is putting so much demands on my cpu that my webcam is kind of glitching here a little bit okay but you see look what happened right where i clicked i got that color right where i clicked i got that color okay you know what i'm going to do i'm going to try to make that smaller that's kind of a huge picture of me so i'm going to come up here let's make this 640 and then let's make this by 360. let's make it a little smaller so maybe it's a little easier to run okay so now i'm going to come in and i'm going to grab this green and then you can see that the green has a value of 125 but the blue has a value of 115. so when opencv looks when you and i look at this we see a green screen when opencv looks at it it sees something that's only a little bit more green than blue it's really it's almost as much blue as green and so you see it it looks at it quite a bit differently all right but that actually worked now the one other thing that i would like to do is i would like to go ahead and i would like to label that little box with what the color is and that way i don't have to look down below okay so we're going to come in and we are after we do the uh x make it that color then i am also going to say that i want to do a cv2 dot put text i want to do a cv2 dot put text and then what do i want to put on there well i want to put on the image x so i've got to put x and that is getting annoying okay i want to put x and then what do i want to put on there i think i'm going to have to make that smaller so that that's not quite as annoying all right so i'm going to put on the image x what text am i going to put i'm going to put the string value of the color okay because you can't just put numbers it's got to be a string so i make clr that little tuple with the blue green red numbers i'm going to make that a string and then i am going to put it where i got to tell it well i'm going to go over an x value of 0 and i'm going to go down about 50 and that should put it up in the kind of like upper left corner if i'm thinking of this right and then i've got to tell it the font so i'm going to do a cv2 dot font and then this hershey complex will probably work and then i am going to need it what else do i need to do here okay i need to tell it i think it's like the font size i'll give it a one and now it wants a color so i'll give it the color zero comma zero comma zero that is black that's turned off uh blue green and red channel so that should be black text and then i think that the last thing is the thickness and i will just give it a thickness of one as well okay so now this if i'm thinking right should put the color on my little color box let's see what happens okay so we're going to come and we're going to click and we're going to get a green and look at that that is boom and that is the color 118 for blue 126 for green and 52 for red so even the green screen has red in it if i click over here look at that 79 87 43 if i click down here 71 77 39 if i click here 121 128 51 now to your eye when you look behind me what do you see you see green and it looks all kind of pretty much the same but to the computer there is a huge difference between this and this okay and this you see all these are all over the place so if i was trying to track on this green what ranges would i look for like what range of of greens and what ranges of blues and there would be certain blues that would go with certain greens and so it becomes an untenable an untunable problem to try to uh to try to track on that or like if you look at my shirt that's blue of 255 204 for green and 236 for red and so this has a bunch of different colors of all types in it okay so do you see the easiest thing to track on is color all right like if you think about your eye you can very very easily you can say this is green this is purple this is sort of flesh tone right but to the computer this is just almost like just crazy random numbers okay so the problem is is that if we're going to try to track on color tracking in the bgr or the rgb color space becomes untenably difficult now i could build an algorithm where we could track on something like let's say this yellow lid okay this yellow lid we could write an algorithm that could track on that yellow lid but it would be painfully difficult it would be painfully difficult for us to identify all the different ranges that would distinguish this from this okay it would become very very difficult so what do we need we need a different system of numbers we need a different way to think about colors and that different way to think about colors is the hsv color space hsv is hue saturation and value okay so there's still three numbers there's the still the same amount of data to map the entire color space but in the hsv color space the computer looks at the color much more like you intuitively look at it and what i have here is i have a color wheel or a three-dimensional color wheel that sort of explains the hsv color space and let me get a little bit more out of your way and the most important number is the hue and the hue is kind of where are you in angle as you go around this color wheel and so just look at the very top of the color wheel and the hue is kind of like what the color is and you can think of it as an angle between 0 and 360. and you can see that there is red and colors around red there is yellow colors around yellow blue colors around blue and this missing slice out of this is kind of like the greens all right so that's the first number is the hue and the way to think of hue is hue is like the color it's like what you think of as color well then what is saturation well that's kind of like how intense the color is and so if you come all the way out here which would be kind of like full saturation that's 255 and if you go all the way back to the center that is a saturation of zero the way you could think of this is imagine that you had blue ink and you took a drop if you had just pure blue ink that would be full saturation saturation of 255. if you took a drop of ink and dropped it in a glass of water it's the exact same color but now it's very very dilute so the saturation might be more like two or three okay and then if you took a drop out of that and then put it in another great big thing of water the saturation would go almost pretty much all the way to zero and so zero saturation would be kind of clear now this is the cool thing look at this up here no matter where you are on hue if you set if you no matter where you are on hue no matter which color you are if you set saturation to zero you go all the way back to what to clear okay so as saturation gets less and less and less all the colors sort of are moving towards clear and you can see that in this little wheel up here okay so sad the hue is really what color it is the saturation is how intense it is and as saturation starts going down below 255 you're kind of diluting it you are diluting it with like clear you could think of it that way well then what is this value nonsense well the value is think about think about adding black to it so if i go all the way up to the top i'm pure blue but as i start coming down if my value is 255 in value then i'm kind of like pure blue and his value begins to come down down down down down down it's like i'm mixing black in it's like i take a drop of this pure blue ink and i put it in black ink okay and you can see that as i come down down down by the time i get all the way to the bottom i'm black so no matter where i am in hue if i put a value of 0 a value of 0 is going to turn any color any hue is going to turn black if value goes to zero if value is 255 then it's pure color and so i mix the hue which is the color i mix it the saturation kind of is pushing it towards clear and the value is pushing it towards black okay so if you go to the center of this pie and go up and down in the center where saturation is zero what are you going to have you're going to have a grayscale because you've sucked all the color out of it think about this because this this color wheel really it's very intuitive and then all of a sudden the numbers that we get from that the numbers that we get from that become very very uh very very intuitive now i got to talk a little bit about what the values are there's the generic hue saturation and value which i've just shown you with this but then how does that map specifically onto the opencv kind of like three numbers right like before i had blue comma green comma red okay how does that map into hue saturation and value so there's still three numbers the first number is hue the second number is saturation and the third number is value okay so still three numbers for every color well let's talk about the easy ones first on saturation zero is all the way to the center it's going to be clear and 255 is all the way out to the edge which is full brightness which is full saturation okay so saturation is going to be a number between 0 and 255. similarly for value uh it's going to go from 0 which is going to be black down here up to 255 which is going to be just straight the color with no none of this darkness mixed in okay so the second number saturation is going to go from 0 to 255. the third number value is going to go from 0 to 255 but but hue is an angle okay so you might think that hue would go between 0 and 360. that would have made a lot of sense right but the problem is we have an 8-bit number and an 8-bit number can only go from 0 to 255. so what they did to keep it intuitive with angle they just said okay let's make it let's make it half the angle and so the hue goes from 0 to 180. so 0 starts here i wish i could point up here 0 look in the upper left up there at the little inset image you see 0 is red and then as i start going in a positive angle when i get to 45 i've gone through yellow and i'm approaching green as i go to 90 degrees i go through green and i'm approaching blue and then as i go to 135 i've gone through blue and i'm approaching purple and then when i go from 135 to 179 i'm going back to red okay and wait why did i say 179 because i've got a hundred and eighty and i start counting at zero so i end at 179 okay i hope that uh i hope that makes sense but you can see by looking at that that really zero or red would be maybe between 0 and 10 red would be between red would be between 0 and 10 would be red red would be between 0 and 10 okay but it would also be between about 169 and 179 okay because the red spans zero so red goes from 0 to 10 degrees from 0 to 10 and also from like 169 to 179 and that would get that whole range of red if you said what's blue that's easier that looks like blue would go from about 110 to 135 but just understand that each click in this h value represents 2 degrees and so 180 takes you all the way around the circle because each increment represents 2 degrees does that make sense i hope it makes sense but now it makes it very very easy it makes it very very easy to understand color because it's more on an intuitive scale i i'm going to actually try to do this i shouldn't try to do this on the fly but let me take let me take this x okay this x array here i guess i better come back over here where you can see me coding shouldn't i okay let's take this x array and let's create a y array and let's say y is cv2 dot cvt color so i'm going to convert color and i'm going to take the x array and then i am going to do cv2 dot i'm going to do a color conversion and i'm going to go from b g r to h s v and so now this y this y array is the x array converted to hue saturation and value and so now this uh i guess i know i think i'm going to have to say that i'm going to have to convert frame because that's where my colors are so i'm going to take the frame that i grabbed i'm going to convert it to the hsv color space and i'm going to call that y okay and now when i get my color i'm going to get my color from not frame but from y what am i doing i'm trying to grab the hsv i'm trying to grab the hsv parameters of where i am and now i think i think at this point everything else should be the same i think everything else should be the same so let's do this it's just the number that i print now is going to be in hsv format that doesn't make sense stop and take a look at it again okay so now when i click here okay it is giving me a hue value of 87. okay let me okay it's giving me a hue value of like 85 84 85 what do you guys notice you see to your eye the background looks the same color now to open cv as i click around what do you notice the hue is always there at about 85 okay 83. so now all of a sudden to me it looks the same and to open cv in the hsv color space it looks the same now the 126 and the 81 the value and the the value and the saturation they're all over the place but you see it doesn't matter because now i can just track on the hue okay now let's come back over here and let's see if that makes sense that is giving me about a 90 okay and yeah if you look over here okay if you look over here about 83 okay about 83 and you are looking in the upper left inset okay if i look in the 80s that would be over here in this green and this green as it is kind of tending towards blue okay so you see all the sudden it makes perfect sense or let's see let's see if i come back over here okay if i come back over here that's where i want to be and now let me click on my forehead and that should be very much towards red okay and if i come back over to the color wheel you can see that 173 would be almost all the way around and it's over there in in that kind of pink going to red region does that make sense let's uh let's see now okay let's look at this right this was the one we were going to want to track on and then if we look at that it's 24 okay where would 24 be oops let's see you weren't seeing the same thing i was saying i'm sorry so let's come over here and now i'm going to look at this i'm going to click on that and now the hue there is 23 and if i come back over here where is in the upper left inset where is 23 well it's halfway to 45 what's right at halfway to 45 it is yellow cc now if i wanted to track on yellow i could say well give me the uh give me the hues that are between 20 and 26 and that would be that little slice that is pretty much yellow okay so in the hsv color space in the hsv color space it is very easy in the hsv color space it is very easy for you to track on color in the rgb color space it is almost impossible to track on color okay i hope this makes sense to you guys i really do i hope this makes sense to you and so i am going to give you a homework here okay i am going to give you a homework and what that homework is is that homework is to go out because i want you to see if you really understand how to deal with pictures as a data array and i want to see if you really understand hsv so what i want you to do is i want you to write a program and what i want that program to do is generate a rainbow i want you to generate an image i want you to generate a window okay i want you to generate a window that has the hsv rainbow i want it to have the hsv rainbow and as you go across your little window as you go across your opencv window i want the hue to change i want the hue to change from 0 to 179 remember you stop at 179 i want the hue to go from 0 to 179 and then up and down i want the saturation to go from 0 to 179 okay now on that one you can go ahead and make the value right there's three numbers hue saturation and value you can only change two of them so go ahead on that picture and make the value 255. so that just basically means that the value isn't going to have that black mixed in okay so you're going to go from 0 to 180 and then as you go down you're going to go from 0 to 255. and then on the second one i want on the rows i want you to go from 0 to 180. i mean on the columns i want you to go from 0 to 180 okay and hue and then in the rows i want you to go on value from 0 to 255 okay now when the value is going from 0 to 255 just set the saturation or just set the saturation to 255. okay i might have said it in a confusing way i'm going to do it i'm going to run the program for you and when i run the program for you i'll describe it again to make sure that the homework is in fact making sense okay let me move over here and i'll show you what the output of the program is okay so in the top window as i go across the columns the hue is changing from 0 to 180. in the top window the saturation as i'm going through the rows the saturation goes from 0 to 255 okay and in all of those the value is 255. now in this bottom window as i go across the rows the hue starts at 0 and the hue across the rows go to 179 and then on the rows i go from that was the column so i start the column at a hue of 0 and i go to a hue as i go across the columns to 180 or 179 now on the rows i start with a value of 0 that's why it's all black across that top row and i go to a value of 255. so the first one the saturation is changing from 0 to 255 as i go through the rows as the value is pinned at 255. in the bottom one the value goes from 0 to 255 as i go through the rows as the saturation is pinned to 255. does that make sense you need to go in and generate these rainbows these two rainbow boxes with what you learned today now this sounds easy but this probably you're going to have to really think about but i promise you between today and the earlier lessons i have given you everything that you need to know in order to be successful with this lesson okay you have everything you need in order to do the homework now if you are able to do this homework i think it would be great if you did a screen capture of it post it to youtube and then leave a comment down below with a link over to your homework solution and then over there when you do the youtube leave a link back to this lesson so if someone comes on it they have context to know what it is that you're trying to do okay if you're able to do it link over to your solution and then leave the comment i am legend okay if you're not able to do it leave the comment i fold it up like a cheap walmart lawn chair guys i feel like this lesson has maybe been a little bit more tedious than some of the earlier lessons i apologize i didn't more succinctly explain the homework but if you go back and listen to it as you're looking at the picture i think you'll see what i am asking you to do okay do it let me know if you're able to do it i would say this is probably one of the more tedious lessons we're going to have in this series but man you've got to understand a couple of things you've got to understand that pictures are nothing but data sets and you can find your way around those data sets and you can create them or you can take them from something else and you can kind of go in and out and interact with these things as data sets and that's sort of like what this is challenging you to do okay guys i hope you're having as much fun taking these lessons as i'm having making them i'm really having a lot of fun i love looking at your homework i love you guys that are posting your homework on youtube and linking back to my video i get a real kick out of seeing this and i hope you guys will continue to do that all right i'm going to wrap it up here if you enjoyed this give me a thumbs up if you haven't subscribed to the channel already be sure to subscribe when you subscribe ring that bell so you'll get notifications when my future lessons come out and i will let you go now paul mcquarter from toptechboy.com i will talk to you guys later
Info
Channel: Paul McWhorter
Views: 2,320
Rating: undefined out of 5
Keywords:
Id: KHcOrNwB32Y
Channel Id: undefined
Length: 53min 28sec (3208 seconds)
Published: Tue Sep 21 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.