Computer Vision Basics: Hough Transform | By Dr. Ry @Stemplicity

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone and welcome to this section I'm super excited to discuss any very important topic in computer vision which I'll call it Huff transport okay and we're actually going to use it directly the Hough transform along with what we learned before about region of interest masking actual and of combine them together to come up with a technique that can detect lane lines for us okay so Afton's for mainly mainly can be used to detect lines in an image okay and let's take a look at what do you mean by an actual Hough transform and how can we actually apply it when in an open CV environment okay so a little bit of math I know you like again I promised you not to cover or not to dig into a lot of theory a lot of equations in mathematics but I like you know there's no way I have to I have to dig a little bit into the mathematics and show you how can we do it kind of a very high level into intuition form so let's assume that I have this line and my objective here is to model that line just get a model that basically tells me the equation of this line we have covered that before and you know and like based basic mathematics that y equals MX plus B where I can represent you know any line as kind of giving me the slope which is M Delta Y by Delta X ok which is slope of my line along with B which is the intercept how can I be intersect intercepting the y-axis okay all right another representation okay or another kind of representation of that line using what we call it the Rho value and theta okay what do you mean so let's assume that I have this line and here I have my origin I can represent that the exact same line using just kind of a different equation okay assuming that I from this from the origin I'm gonna draw a perpendicular line to my to my desired line okay again this is my line that I'm looking for I'm gonna draw a perpendicular line to it okay I can represent the equation of this line using Rho and theta primers okay what do you mean so theta is simply the angle with the horizontal line that's the theta and Rho it's simply the distance from the origin perpendicular to the line which is this distance so I can present this line using these two Rho and theta parameters okay it's kind of a different representation of the line why I mean why again the question is important quest what are you teaching me this I'm teaching you this because we're gonna use them to actually kind of use these two parameters okay to obtain lines from the image I'm gonna show you how which is very very smart kind of technique I'm gonna be used to detect lane lines within any within any image or not lane lines any straight lines I'm gonna use it again for some driving cars to detect the lane lane lines alright so again row with the perpendicular distance from the origin to the line and theta is the angle formed by this perpendicular line with the horizontal axis from this perpendicular line the resultant axis and this is simply the equation of again of this of the straight line the exact same straight line I can x multiplied by cosine theta plus y times sine theta that would give me 0 then and that's kind of the two equations of a straight line exact same straight line alright let's make you know use of what we learn all right all right so let's assume that I have my my vehicle and I'm taking a camera image from this vehicle okay what I'm looking for then I'm looking for the equation or I'm look I'm searching for the line in order to search for the line and search for the equation of that line so again I mentioned the equation of any line not specifically Lane line just any line is y equals to MX plus B or X cosine theta plus y sine theta equals to Rho okay all right so these simply put what we have just described is what we call it in the image space so in the actual image I can represent the equation of the line using one of these two equations okay however instead of using the image space I'm gonna use one call at half space which is a different kind of representation of space okay what do you mean so each line in the image space so this line of the image space we're going to be represented by a dot in what we call it half space here okay all right simply put in the half space I'm going to put here my M which is the slope of the lines of all lines here I'm going to put the B which is again intercept with the y-axis and each of the line again I mentioned each of this line can be represented by y equals MX plus B so it has specific slope and a specific intercept with the y-axis M no than B note simply put I can take this and put it in the half space at just one dot again this dot represents a straight line which is M and B okay in the same fashion I can represent it in the half space again using this equation I can represent the exact same point using what we call it Rho and theta parameters or Rho and theta values all right again why are you teaching me this why are we going from you know like like an image space so call it half space okay the whole idea is is that I want it kind of to scan my image space that's the whole intuition okay I'm going to show you all the details in the next slide but the whole idea is I need to look for the line okay so in order to look for that line what I'm gonna do they're gonna kind of a scan the entire image in a way and each time or each of the points I will try to get you know Rho and theta for these different points so along the point along whatever points I'm gonna get em I'm gonna get Rho and theta again Rho and theta or M and B M and B all the time okay and are gonna draw that here in what we call it my Huff's half space so simply in the half space are gonna be drawing although all the representing the entire image even we'll call it M and B coordinates or Rho and theta coordinates all right and simply put we're gonna do what we call kind of a voting voting exercise in simple forms every every time you're gonna be doing you know a transformation from an image image space to half space you will see kind of the M and B has been repeated several times which kind of wrote like kind of a voting way which is kind of an accumulated accumulator you know it's kind of us in this point which is indicating m and B or Rho and theta you will see that there is kind of you know like a like a like an accumulator that shows okay there's like 80 points or let's say a hundred points which means that's kind of the vote that tells you okay maybe this point has a line in it when you shift from here back to the image space okay if it's not clear I'm gonna show you an exact example moving forward but that's the whole idea of why we do we actually move from an image space to what we call it half space okay simply put and then I represent every line in the image space by a dot in the half space okay again this dot can be M and B or can be Rho and theta let's again take Allan other-- look an actual practical example let's assume that I have this image which is again pure white image with two lines horizontal lines in it the blue line and the yellow line okay and this image is hundred 100 image with horizontal line in the middle I try to include the details here as much as possible I get to avoid any confusion so a bit confusing at first but once we run it you'll see it's that's very easy first we're gonna create what color 2d matrix we're gonna create a matrix okay that has all the rows and all the Thetas alright kind of all the rows here and all the Thetas in here okay and we'll set it all of it to zeros so simply put we don't know where the line is which is gonna create a matrix that I quoted set 0 into it all right first step I'm gonna select the first point on the line so let's assume they're gonna select the first point here on that line okay so for each point what I'm going to do then I'm going to kind of scan the entire angles entire theta okay so we're gonna do a rotation from let's say 0 1 2 and so on up until let's say 180 ok so I'm gonna draw try simply different values of theta all right and for each value I'm gonna obtain the row back again alright so again simply put here I have this equation I I know this point so I know X and I know why and I'm gonna do it I'm gonna try different values of theta I'm gonna try theta L 1 so here I have all the values here unknown however Rho is unknown so basically I'm gonna substitute in this equation get Rho value all right all right which means at this point I'm gonna get to Rho and theta all right I'm gonna put it here in this matrix okay and then the next step what I'm gonna do is I'm gonna every row and set appeared what I'm gonna do is they're gonna go let's take to the next point all right and do the exact same exercise again come again with row and set of values I'm gonna come to the next point as well and do it again the exact same exercise though and set of values so you guys can see here simply put the row and theta value which is here gonna be 50 and 90 all right again it's little bit confusing but you know like better mine so bear with me so 50 and 90 indicates that okay row which is again distance from the origin it sits in the center exactly so here the distance is 50 and the angle is 90 right which is the angle from this the origin to the line is 90 degrees and that's why you will see in that specific cell which is 50 and 90 okay every time going to be incrementing it by one all right so again as you move forward for example this line you will see that every time all the points here on the line have the 50 and 90 Rho and theta all right all of these points have 50 and 90 as long every time you draw a perpendicular line from the origin to that line you can get the exact same value it's at the same distance 50 and have this exact same angle 90 simply put every time you're gonna move to this line you get a kind of increase their accumulator within that value here by one so you're increasing it by 1 1 1 1 which means simply when you go to the half space when you see a point in the half space that has a lot of values the accumulator is very high it's very large number that indicates the line has been found in a very simple form okay all right so simply put this line is representing the Hough transform as just 1 dot okay indicating a lot of intersecting simply points or a lot of accumulate accumulated it's kind of you know like a lot of values within that grid that we created out of 0 out of nothing ok so simply put cell 50 on mind you will be voted up the accumulator with maximum votes simply indicates a line so a line has been indicating the order detected in the image all right what about the yellow line so this line has this exact same angle so you guys can see this sale theta at the same so nightly the same however the distance from the origin is around here we set it to 25 pretty much okay so the distance from here to here is around 25 this is from here to the blue line is 50 and that's why you would see here if we have two lines you will see that this accumulated has been accumulated as well increases when indicating there is another line at 2590 location okay again it's kind of a different representation of the exact same thing in all colors and Hough transform as opposed to the image transform okay alright so what I'm gonna do with this simply put I'm gonna apply kind of you know like fine tough lines okay kind of the function I'm gonna be using within OpenCV that can gives me exactly what are the row and Thetas of all the lines that have been found in the image it's really powerful it's really intuitive and it's so going to be used to detect line lines within an image all right okay so how can we put how can we apply it then actually use again CV to those tough lines that are provided with the image and they're provided with these parameters gonna provide it with row accuracy theta accuracy and threshold value simply puts here I'm gonna define in general it let's assume again I put let's say 1 and PI divided by 180 which means 1 degrees and then 240 that would kind of create our resolution all right this is the resolution within the parameter Rho how many pixels I'm going to need my resolution within a parameter Rho I need theta which is my resolution of how many angles are gonna be doing you guys remember where the grid okay that indicates the the grid here how many times are they evaluating and rotating every one degree every two degrees and so on alright and that's the kind of the value is gonna be doing the row theta and the threshold as well threshold which is kind of you know the the vote you guys remember every time we actually increased accumulator that's kind of you know the vote how many times do I need to include if I put let's say 240 that's kind of the minimum vote that I need to detect okay that's a line that's a flag that tells me okay I found the line that's kind of the minimum special that I need okay all right and simply put CV to those half lines we're gonna give me a return all the lines that has been found in the image which is amazing because now I can basically select which line is perfect I can know the slope I can then Center my vehicle I can do wonders with it moving forward after we detect the lines within within the image all right and that's pretty much all I have for this section I hope you guys enjoyed it and now to the fun part an actually implemented within and then and the Python environment and then afterwards we're gonna do we're gonna combine the region of interest masking along with the hop transformation to actually detect a lane line within an image I hope you guys enjoyed it and see you in the next section
Info
Channel: Stemplicity
Views: 30,649
Rating: undefined out of 5
Keywords: Computer vision, hough transform, machine learning, self driving cars, hough transform opencv, opencv, hough transform python, hough transform matlab
Id: 6yVMpaIoxIU
Channel Id: undefined
Length: 13min 55sec (835 seconds)
Published: Fri Jun 28 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.