1 00:00:00,430 --> 00:00:00,840 OK. 2 00:00:00,930 --> 00:00:04,890 So let's open up a four point four which is matching Contos shape. 3 00:00:05,050 --> 00:00:07,810 So that's open it here really have it open. 4 00:00:07,890 --> 00:00:14,500 So shape matching shape matching is actually a pretty cool technique implemented in open C.v. 5 00:00:14,700 --> 00:00:18,500 So the code looks a little bit confusing but it's actually quite simple. 6 00:00:18,570 --> 00:00:20,310 So let's run the code and see what's going on. 7 00:00:20,310 --> 00:00:27,000 Fiercly So we have this is a ship template image dubber trying to find in a lot of image. 8 00:00:27,320 --> 00:00:28,020 And here we go. 9 00:00:28,020 --> 00:00:30,430 So this is the image we're trying to find it here. 10 00:00:30,840 --> 00:00:35,130 And we have identified a sheep here is more similar to the shape here. 11 00:00:35,460 --> 00:00:40,770 Alice according to the algorithm there are different methods of doing the proper approximations or ship 12 00:00:40,770 --> 00:00:41,160 matching. 13 00:00:41,160 --> 00:00:42,770 I should say so. 14 00:00:42,810 --> 00:00:44,380 This one here works pretty well. 15 00:00:44,400 --> 00:00:46,150 It actually found a close match. 16 00:00:46,440 --> 00:00:48,640 So now let's see what's going on here. 17 00:00:48,990 --> 00:00:53,360 So as I said we load a template image and here that's a four star. 18 00:00:53,640 --> 00:01:00,330 And that's cool a template image and then we actually have luto a target image here which is the focal 19 00:01:00,450 --> 00:01:01,540 shapes to match. 20 00:01:01,650 --> 00:01:05,070 Or you can consider it to be much too. 21 00:01:05,110 --> 00:01:05,660 All right. 22 00:01:05,660 --> 00:01:10,760 And then what we do next is we find floozie Trishul those images here. 23 00:01:11,000 --> 00:01:15,680 That's part of the procedure that we use in this in this code here. 24 00:01:15,800 --> 00:01:19,730 And then after that we find CONTO is the first template image. 25 00:01:19,730 --> 00:01:25,820 So we extract all Kontos into this image then we sought the Contos and largest A small This just in 26 00:01:25,820 --> 00:01:31,430 case there were any noisy contours or discrepancies because we do know we only want the largest Cantal 27 00:01:33,310 --> 00:01:37,560 and necks since we have sorted Contos by in order from largest the smallest. 28 00:01:37,870 --> 00:01:41,110 We actually remember previously when there's a white background. 29 00:01:41,210 --> 00:01:45,520 The First Consul was always the big box big white box of the image frame. 30 00:01:45,610 --> 00:01:47,050 You can consider it. 31 00:01:47,170 --> 00:01:52,490 So we actually have to get a second largest contour here so we extract Descanso now and then what we 32 00:01:52,510 --> 00:01:58,700 do we actually again find Contos now in our target image which was a shapes to match to be matched to 33 00:01:58,890 --> 00:02:00,180 I should say. 34 00:02:00,280 --> 00:02:01,870 So we do that here. 35 00:02:02,590 --> 00:02:09,120 And then OK so then we actually know loop through all contours in our target image. 36 00:02:09,300 --> 00:02:13,570 And this is where we actually use C-v to match shapes function. 37 00:02:13,590 --> 00:02:14,550 So what we do here. 38 00:02:14,590 --> 00:02:19,710 This is a template Cantal dimply control was actually what we found previously. 39 00:02:20,630 --> 00:02:21,200 Right. 40 00:02:23,230 --> 00:02:27,240 And C see the contours in the control file. 41 00:02:27,310 --> 00:02:29,860 So we're going to target file has multiple contours. 42 00:02:29,850 --> 00:02:31,790 There are multiple shapes in that file. 43 00:02:31,870 --> 00:02:35,300 So that's where we're looping through each of the contours in that file here. 44 00:02:35,680 --> 00:02:41,600 And these parameters here which are different method and method parameters these are for first method 45 00:02:41,650 --> 00:02:47,260 it describes the CONTO matching type which will get into in a moment and then dispersement here which 46 00:02:47,260 --> 00:02:48,950 is just basically a default Perlman's. 47 00:02:49,300 --> 00:02:53,710 Don't interfere with that is probably going to be some works in the open Sivy is an open source project 48 00:02:53,710 --> 00:02:58,390 is probably going to be some work being done on disorder and um but for now it's not utilized totally. 49 00:02:58,420 --> 00:03:02,910 So just leave it at zero and it's actually a float zero apparently. 50 00:03:02,950 --> 00:03:08,160 So what this function returns is a much value. 51 00:03:08,550 --> 00:03:12,190 And basically Lua means a close a match to original image. 52 00:03:12,210 --> 00:03:19,500 If we were matching the exact contours like axium scale and size in order the match would be basically 53 00:03:19,500 --> 00:03:20,560 zero. 54 00:03:20,570 --> 00:03:26,270 However in this case we're looking for the closest match so we can try a different much method here 55 00:03:26,550 --> 00:03:28,130 which I'll get into in one second. 56 00:03:29,540 --> 00:03:35,150 So after we do so after we print the much value here what we do here is that just by trial and error 57 00:03:35,300 --> 00:03:40,890 I figured out that anything that's on that is value of point 1 5 is going to be the closest much or 58 00:03:40,890 --> 00:03:44,960 the much that's closest to the starship on the image. 59 00:03:44,960 --> 00:03:47,230 So that's how we determine whether it's a match or not. 60 00:03:47,390 --> 00:03:53,540 And if it is a match we make that CONTO that we examining in this loop here equal to the closest CONTO 61 00:03:53,540 --> 00:03:55,730 match either way as close as is. 62 00:03:55,750 --> 00:03:59,290 No are here. 63 00:03:59,890 --> 00:04:08,600 And then once that's done we actually draw close control control using draw control as an output. 64 00:04:08,640 --> 00:04:11,050 So that's pretty much how this could works here. 65 00:04:11,070 --> 00:04:12,850 So let's run it one more time. 66 00:04:12,980 --> 00:04:13,970 Real stuff. 67 00:04:14,250 --> 00:04:18,570 And this is a CONTO the Crucis much to CONTO of the star. 68 00:04:18,650 --> 00:04:22,170 So remember I said there are actually different matching methods here. 69 00:04:22,460 --> 00:04:27,660 Despina to parameter this much value saurian is much ships function. 70 00:04:27,800 --> 00:04:34,160 So if you go to open civies documentation here which I'll put a link in our file actually just to see 71 00:04:34,160 --> 00:04:42,300 if keeping make this a mock document you guys do they go. 72 00:04:42,410 --> 00:04:46,360 So if you look at this here are actually tree methods here is Contos much. 73 00:04:46,380 --> 00:04:49,530 I want to add a tree and this is the mathematics behind it. 74 00:04:49,530 --> 00:04:50,570 What's going on here. 75 00:04:50,910 --> 00:04:52,700 So feel free to experiment with it. 76 00:04:52,710 --> 00:04:56,470 We can try changing it to here and see what happens. 77 00:04:56,490 --> 00:04:57,710 It does work and. 78 00:04:57,750 --> 00:05:00,970 But you can see the values here are indeed different. 79 00:05:01,020 --> 00:05:06,270 In fact they're pretty much all under 1.5 here. 80 00:05:06,390 --> 00:05:12,390 So we actually pretty much got lucky because last one here was actually too much essentially and that's 81 00:05:12,390 --> 00:05:16,380 why Close's counter can't count or was equal to see. 82 00:05:16,380 --> 00:05:21,960 So you can play with this and see try different values that up and again here. 83 00:05:22,400 --> 00:05:23,140 So yeah. 84 00:05:23,150 --> 00:05:27,980 So that's how we match onto a ship using this much shape's function in open C-v.