AI_DL_Assignment / 5. OpenCV Tutorial - Learn Classic Computer Vision & Face Detection (OPTIONAL) /27. Approximating Contours & Finding Their Convex Hull - Clean Up Messy Contours.srt
| 1 | |
| 00:00:00,660 --> 00:00:04,120 | |
| So what we're going to look at now is called approximating contours. | |
| 2 | |
| 00:00:04,480 --> 00:00:06,700 | |
| So fleecy let's open this file here. | |
| 3 | |
| 00:00:06,750 --> 00:00:08,310 | |
| This is 4.3. | |
| 4 | |
| 00:00:08,700 --> 00:00:09,530 | |
| 4.3 here | |
| 5 | |
| 00:00:13,300 --> 00:00:16,060 | |
| and that's actually run this could see what's going on. | |
| 6 | |
| 00:00:16,420 --> 00:00:20,680 | |
| So I have a very crudely drawn house that I did by hand to do a splint. | |
| 7 | |
| 00:00:20,920 --> 00:00:22,550 | |
| Thank you very much. | |
| 8 | |
| 00:00:22,660 --> 00:00:26,330 | |
| And this is what happens when we extract contours and approx. | |
| 9 | |
| 00:00:26,340 --> 00:00:31,360 | |
| I used a bonding rectangle for Contos so you can see we've have we have a bonding rectangle for the | |
| 10 | |
| 00:00:31,360 --> 00:00:32,530 | |
| entire house. | |
| 11 | |
| 00:00:32,680 --> 00:00:33,810 | |
| Then one for the roof. | |
| 12 | |
| 00:00:33,820 --> 00:00:39,460 | |
| So I'm guessing find Quanto has found contours of this triangle here than the door and then the bottom | |
| 13 | |
| 00:00:39,460 --> 00:00:40,560 | |
| half of the hose here. | |
| 14 | |
| 00:00:40,810 --> 00:00:42,130 | |
| So that's pretty cool. | |
| 15 | |
| 00:00:42,170 --> 00:00:45,720 | |
| Now there they're prox to approx function is what we're going to look at. | |
| 16 | |
| 00:00:45,720 --> 00:00:46,300 | |
| No. | |
| 17 | |
| 00:00:46,650 --> 00:00:52,660 | |
| And what does that actually as you can see here trace approximate or contour shape better. | |
| 18 | |
| 00:00:53,140 --> 00:01:00,770 | |
| So this may look a lot similar to the actual initial contour operation here. | |
| 19 | |
| 00:01:00,900 --> 00:01:04,450 | |
| However what it does it actually tries to approximate a polygon here. | |
| 20 | |
| 00:01:04,500 --> 00:01:06,060 | |
| So let's take a look at a function here. | |
| 21 | |
| 00:01:10,190 --> 00:01:11,660 | |
| So you can see you know a loop here. | |
| 22 | |
| 00:01:11,660 --> 00:01:12,490 | |
| We're actually doing. | |
| 23 | |
| 00:01:12,530 --> 00:01:14,030 | |
| We're looking through the Contos again. | |
| 24 | |
| 00:01:14,030 --> 00:01:15,950 | |
| We found find Contos right here. | |
| 25 | |
| 00:01:16,160 --> 00:01:19,650 | |
| And refining all contours and doing no approximation here. | |
| 26 | |
| 00:01:19,730 --> 00:01:24,380 | |
| Maybe I should have done a simple approximation although it wouldn't have made much difference in this | |
| 27 | |
| 00:01:24,380 --> 00:01:25,190 | |
| example here. | |
| 28 | |
| 00:01:28,110 --> 00:01:35,700 | |
| Going back to Otari approximate poly DP function here in TV2 This is how we approximate Contos is actually | |
| 29 | |
| 00:01:35,700 --> 00:01:41,430 | |
| very useful if you have a noisy image with jagged contours and you know a ship is supposed to be square | |
| 30 | |
| 00:01:41,490 --> 00:01:47,880 | |
| or a triangle whoever you're getting maybe multiple edges and that polygon dysfunction actually basically | |
| 31 | |
| 00:01:48,770 --> 00:01:51,020 | |
| approximates approximates it for you. | |
| 32 | |
| 00:01:51,030 --> 00:01:54,390 | |
| So let's look at the parameters it takes in here. | |
| 33 | |
| 00:01:54,410 --> 00:01:55,410 | |
| So at a high level. | |
| 34 | |
| 00:01:55,430 --> 00:01:57,500 | |
| Describe exactly what his function is doing. | |
| 35 | |
| 00:01:57,710 --> 00:02:04,280 | |
| So it takes tree parameters into consideration here it takes input CONTO something called an approximation | |
| 36 | |
| 00:02:04,310 --> 00:02:06,520 | |
| accuracy which I'll discuss shortly. | |
| 37 | |
| 00:02:06,650 --> 00:02:11,570 | |
| And basically what do we want on a closed polygon or open polygon. | |
| 38 | |
| 00:02:11,640 --> 00:02:15,080 | |
| So is being preferred in pretty much all cases I believe. | |
| 39 | |
| 00:02:15,200 --> 00:02:21,020 | |
| So let's take a look at approximation accuracy approximation accuracy is basically how detailed the | |
| 40 | |
| 00:02:21,020 --> 00:02:25,910 | |
| whole finally agree and do you want the approximation to be if you want to low accuracy and a good rule | |
| 41 | |
| 00:02:25,910 --> 00:02:28,960 | |
| of thumb here is 5 percent of the contour perimeter. | |
| 42 | |
| 00:02:29,000 --> 00:02:35,660 | |
| However if you go to high efficiency with accuracy let's look at c using Point 1 here. | |
| 43 | |
| 00:02:35,660 --> 00:02:40,870 | |
| Let's see what happens it actually does something pretty weird it actually tries to approximate the | |
| 44 | |
| 00:02:40,870 --> 00:02:44,350 | |
| house into the freedom of the house into a triangle. | |
| 45 | |
| 00:02:44,350 --> 00:02:45,670 | |
| That's clearly not good. | |
| 46 | |
| 00:02:45,940 --> 00:02:46,450 | |
| So what if. | |
| 47 | |
| 00:02:46,470 --> 00:02:53,820 | |
| What about if we use point 0 1 as you can see it actually tries to match the house even closer. | |
| 48 | |
| 00:02:53,830 --> 00:02:58,810 | |
| So what I suggest is that you maybe maybe play with these values a bit when he actually works fairly | |
| 49 | |
| 00:02:58,810 --> 00:03:00,700 | |
| well in this case here. | |
| 50 | |
| 00:03:00,940 --> 00:03:06,580 | |
| Basically the accuracy or to reassure to perimeter the more precise the approximation is going to be | |
| 51 | |
| 00:03:07,030 --> 00:03:13,410 | |
| and the higher value here the more logic green that the approximation is going to be. | |
| 52 | |
| 00:03:13,660 --> 00:03:17,310 | |
| So let's keep that in mind when you're actually playing with the accuracy parameter here. | |
| 53 | |
| 00:03:18,640 --> 00:03:23,440 | |
| OK so let's move on to the convex hull and the convex hole is an interesting concept and it's actually | |
| 54 | |
| 00:03:23,440 --> 00:03:27,070 | |
| run Decoud to illustrate this. | |
| 55 | |
| 00:03:27,200 --> 00:03:31,110 | |
| So as you can see we have a hand here sort of like a blue. | |
| 56 | |
| 00:03:31,260 --> 00:03:37,900 | |
| And right now and continuing we have what is called the convex hull not a convex hole. | |
| 57 | |
| 00:03:37,910 --> 00:03:43,670 | |
| Basically if you can kind of figured out from this image here it looks a different do outer edges here | |
| 58 | |
| 00:03:43,760 --> 00:03:46,590 | |
| and it draws lines to each edges here. | |
| 59 | |
| 00:03:46,610 --> 00:03:54,410 | |
| Basically it's what you call the smallest polygon that can fit or the object itself and HUD's found | |
| 60 | |
| 00:03:54,440 --> 00:03:56,410 | |
| it actually is pretty simple as well. | |
| 61 | |
| 00:03:58,260 --> 00:04:04,140 | |
| So all that's happening here is that in this loop here we're digging contours that we found here. | |
| 62 | |
| 00:04:04,560 --> 00:04:06,660 | |
| There's actually two ends of quid I'll explain shortly here. | |
| 63 | |
| 00:04:06,660 --> 00:04:08,570 | |
| It's not too critical just something it does. | |
| 64 | |
| 00:04:08,610 --> 00:04:08,870 | |
| I did. | |
| 65 | |
| 00:04:08,870 --> 00:04:16,850 | |
| And just to show you guys and using the CV to convex whole function it generates a whole data type here | |
| 66 | |
| 00:04:16,920 --> 00:04:18,320 | |
| which is actually in tree. | |
| 67 | |
| 00:04:18,600 --> 00:04:24,540 | |
| And then we put the saree into distro Kontos which takes in a list function a list variable I should | |
| 68 | |
| 00:04:24,540 --> 00:04:30,180 | |
| say and we just draw all the contorts off the image. | |
| 69 | |
| 00:04:30,530 --> 00:04:32,680 | |
| So that's all there is to it and convex whole. | |
| 70 | |
| 00:04:32,960 --> 00:04:39,200 | |
| It's actually quite simple to implement and use this sort of line of code is actually when you use to | |
| 71 | |
| 00:04:39,380 --> 00:04:42,170 | |
| retrieve list method what happens is that. | |
| 72 | |
| 00:04:42,200 --> 00:04:44,730 | |
| Oh mislaying let's just keep this. | |
| 73 | |
| 00:04:44,770 --> 00:04:45,470 | |
| Whoops. | |
| 74 | |
| 00:04:48,130 --> 00:04:49,130 | |
| And do that. | |
| 75 | |
| 00:04:49,230 --> 00:04:51,650 | |
| Let's just keep this here the same. | |
| 76 | |
| 00:04:51,690 --> 00:04:56,430 | |
| So let's run the code again and you'll see a box drawn over this image here. | |
| 77 | |
| 00:04:56,700 --> 00:05:02,590 | |
| And what happens is that every time you find a console and a white image here it actually identifies | |
| 78 | |
| 00:05:02,590 --> 00:05:05,530 | |
| the white background itself as a conto. | |
| 79 | |
| 00:05:05,610 --> 00:05:09,260 | |
| If it was a black image it wouldn't have happened in this way. | |
| 80 | |
| 00:05:09,390 --> 00:05:17,070 | |
| So to get rid of that which happens what I do I tend to do sometimes just use this little lines of code | |
| 81 | |
| 00:05:17,070 --> 00:05:22,890 | |
| here that just if I wanted all Kontos but I wanted to eliminate that largest CONTO I saw the Contos | |
| 82 | |
| 00:05:22,890 --> 00:05:30,930 | |
| Bay Area and they just use non-pay to index it at everything except the first or largest Hanzal and | |
| 83 | |
| 00:05:30,930 --> 00:05:32,460 | |
| that's simply what they do here. | |
| 84 | |
| 00:05:32,610 --> 00:05:39,340 | |
| So this is a way to get rid of that first box or an entire image and generally just decline to be where | |
| 85 | |
| 00:05:39,370 --> 00:05:40,950 | |
| I want to look at here. | |