AI_DL_Assignment / 5. OpenCV Tutorial - Learn Classic Computer Vision & Face Detection (OPTIONAL) /23. Perspective & Affine Transforms - Take An Off Angle Shot & Make It Look Top Down.srt
| 1 | |
| 00:00:00,780 --> 00:00:05,010 | |
| Let's take a step back and look at fine and none fine transforms again. | |
| 2 | |
| 00:00:05,400 --> 00:00:11,800 | |
| So imagine you have an image like this here where we have this is clearly not fine. | |
| 3 | |
| 00:00:11,880 --> 00:00:16,900 | |
| Transform off an original top down flat image here you can see the lines here. | |
| 4 | |
| 00:00:16,950 --> 00:00:21,510 | |
| They're not parallel anymore and they're actually going to join in some feature spot maybe some way | |
| 5 | |
| 00:00:21,510 --> 00:00:21,930 | |
| up here. | |
| 6 | |
| 00:00:21,930 --> 00:00:29,310 | |
| FLATOW So what it means is that if we have four points here we can actually use an open civic function | |
| 7 | |
| 00:00:29,790 --> 00:00:35,340 | |
| to actually watch this transfer this image here and get an image like this. | |
| 8 | |
| 00:00:35,370 --> 00:00:41,100 | |
| So clearly we can take a skewed image once we're aware of the four points of the corner and get back | |
| 9 | |
| 00:00:41,100 --> 00:00:43,220 | |
| to your original image. | |
| 10 | |
| 00:00:43,250 --> 00:00:46,380 | |
| So let's take a look at that implementing that in some code. | |
| 11 | |
| 00:00:46,630 --> 00:00:46,900 | |
| OK. | |
| 12 | |
| 00:00:46,910 --> 00:00:51,020 | |
| So let's look at implementing that perspective transform that we just saw. | |
| 13 | |
| 00:00:51,020 --> 00:00:55,800 | |
| So you remember we firstly need the coordinates of the four corners and the original image. | |
| 14 | |
| 00:00:55,880 --> 00:00:57,550 | |
| So that's what we actually have here. | |
| 15 | |
| 00:00:57,560 --> 00:00:59,390 | |
| These are the four points here. | |
| 16 | |
| 00:00:59,430 --> 00:01:05,930 | |
| We're basically combining it into points 3 here comprise of these four quadrants and then so it is that | |
| 17 | |
| 00:01:06,120 --> 00:01:14,420 | |
| these will be called points then we have points B which is do up which is output which is a point that | |
| 18 | |
| 00:01:14,430 --> 00:01:16,330 | |
| we let's go back to the image here. | |
| 19 | |
| 00:01:16,350 --> 00:01:17,980 | |
| These are the points that we want to define here. | |
| 20 | |
| 00:01:17,970 --> 00:01:21,670 | |
| So that's a typical for standard size. | |
| 21 | |
| 00:01:22,110 --> 00:01:25,800 | |
| We need to get the data so that it actually knows what to transform it to. | |
| 22 | |
| 00:01:26,190 --> 00:01:32,460 | |
| So what we do know we actually use these two points is two sets of points here with this open CV function | |
| 23 | |
| 00:01:32,520 --> 00:01:34,480 | |
| called Get perspective transform. | |
| 24 | |
| 00:01:34,770 --> 00:01:40,920 | |
| What this does it actually generates a matrix and this matrix here is is basically the transform that | |
| 25 | |
| 00:01:40,920 --> 00:01:45,030 | |
| basically transforms points to points B. | |
| 26 | |
| 00:01:45,270 --> 00:01:51,480 | |
| And then we use what perspective that function you may have seen previously to actually generate the | |
| 27 | |
| 00:01:51,480 --> 00:01:57,270 | |
| or to use this sort of matrix here and generate the output image to be called warped here. | |
| 28 | |
| 00:01:57,660 --> 00:02:00,600 | |
| And this is the final size of the image we want to see. | |
| 29 | |
| 00:02:00,600 --> 00:02:02,860 | |
| So as you can see it's actually lines up with this here. | |
| 30 | |
| 00:02:02,910 --> 00:02:07,020 | |
| These would have four coordinates of the output image that we wanted. | |
| 31 | |
| 00:02:07,020 --> 00:02:15,690 | |
| So let's run this good and voila we get the actual warped page here. | |
| 32 | |
| 00:02:16,260 --> 00:02:20,700 | |
| If you wanted to do something smarter you'd probably write an algorithm that gets to CONTO of this image | |
| 33 | |
| 00:02:21,150 --> 00:02:26,550 | |
| that automatically gets the locations of the corner points then feeds it in and then we run everything | |
| 34 | |
| 00:02:26,580 --> 00:02:27,840 | |
| automatically. | |
| 35 | |
| 00:02:27,870 --> 00:02:31,950 | |
| It's actually not too hard to build is actually a low some blogs online that actually do it for you. | |
| 36 | |
| 00:02:33,250 --> 00:02:37,410 | |
| So we've just seen how we generated Imitrex for none I transform. | |
| 37 | |
| 00:02:37,500 --> 00:02:41,060 | |
| But what about affine transform that should be simpler right. | |
| 38 | |
| 00:02:41,070 --> 00:02:46,900 | |
| And indeed it is you only need tree coordinates to actually generate the find transform. | |
| 39 | |
| 00:02:46,900 --> 00:02:49,240 | |
| So similarly we have points in B. | |
| 40 | |
| 00:02:49,420 --> 00:02:49,830 | |
| We are. | |
| 41 | |
| 00:02:49,860 --> 00:02:52,310 | |
| We actually use a different image here and there's a reason for that. | |
| 42 | |
| 00:02:52,320 --> 00:02:53,780 | |
| Also we use shortly. | |
| 43 | |
| 00:02:54,100 --> 00:02:58,240 | |
| So we have tree coordinates for points in b tree coordinates for Point B. | |
| 44 | |
| 00:02:58,240 --> 00:03:05,050 | |
| We use get affine transform as opposed to get perspective transform and we similarly implement those | |
| 45 | |
| 00:03:05,050 --> 00:03:11,020 | |
| transforms using Wolpoff when we just switched to see I would call them Andrews which is similar to | |
| 46 | |
| 00:03:11,020 --> 00:03:13,350 | |
| using the actual dimensions here. | |
| 47 | |
| 00:03:13,660 --> 00:03:18,310 | |
| We just take it directly from the image and let's run this code here. | |
| 48 | |
| 00:03:18,670 --> 00:03:20,500 | |
| So as you can see these are two | |
| 49 | |
| 00:03:23,530 --> 00:03:25,380 | |
| ships that we wish to transform. | |
| 50 | |
| 00:03:25,400 --> 00:03:28,190 | |
| So let's press any key and continue. | |
| 51 | |
| 00:03:28,190 --> 00:03:35,180 | |
| And this is the affine transform as you can see it as I find transform actually rotated the image slightly | |
| 52 | |
| 00:03:35,720 --> 00:03:41,840 | |
| didn't just scale anything but as you can see clearly all the lanes Montie and parallelism here. | |
| 53 | |
| 00:03:42,200 --> 00:03:45,510 | |
| So that's one of the main points of transforms. | |
| 54 | |
| 00:03:45,590 --> 00:03:51,500 | |
| So I hope you get a feel of using these functions here are actually quite handy and quite important | |
| 55 | |
| 00:03:51,500 --> 00:03:53,930 | |
| when doing more complicated stuff in open C-v. | |