1 00:00:00,000 --> 00:00:01,068 [No audio] 2 00:00:01,093 --> 00:00:04,590 Well, I hope you solve the exercise, and 3 00:00:04,590 --> 00:00:07,350 I believe it was not a difficult one. My 4 00:00:07,350 --> 00:00:09,810 purpose there was to get you used to 5 00:00:09,810 --> 00:00:13,650 with the OpenCV code, and also why not 6 00:00:13,680 --> 00:00:16,890 to practice a for loop. So, as you can 7 00:00:16,890 --> 00:00:19,740 imagine, this exercise will be solved by 8 00:00:19,740 --> 00:00:23,040 using a for loop. So, let me go through 9 00:00:23,040 --> 00:00:26,430 the code line by line quickly. So, we 10 00:00:26,430 --> 00:00:29,940 have to import OpenCV, so cv2 and the global 11 00:00:29,965 --> 00:00:33,020 library. If you can recall it 12 00:00:33,045 --> 00:00:36,390 what a globe does is that it finds a path names 13 00:00:36,420 --> 00:00:40,320 of some files given a certain pattern. 14 00:00:40,590 --> 00:00:43,410 So, in this case, for instance, I have 15 00:00:43,410 --> 00:00:48,030 this jpg files here, so, 1, 2, 3, 4, 5 images, 16 00:00:49,140 --> 00:00:52,920 and I said, Okay, create a list of file 17 00:00:52,920 --> 00:00:56,460 names that contain everything in the 18 00:00:56,460 --> 00:00:58,860 first part, and then jpg as 19 00:00:58,890 --> 00:01:02,388 extension. So that will create a list such as, 20 00:01:04,099 --> 00:01:07,115 say, like C and then the path 21 00:01:07,140 --> 00:01:10,500 here and then galaxy.jpg, and 22 00:01:10,500 --> 00:01:12,900 then the other image path and so on. 23 00:01:13,696 --> 00:01:15,930 You'll get the idea, and then what we need 24 00:01:15,930 --> 00:01:18,600 to do is iterate through this list for 25 00:01:18,600 --> 00:01:21,600 each path, image path in the list, in this 26 00:01:21,600 --> 00:01:25,170 list, we'll do these operations for each 27 00:01:25,170 --> 00:01:29,040 of the list items. So first, we will 28 00:01:29,040 --> 00:01:33,090 read that image path. Okay, that image 29 00:01:33,090 --> 00:01:35,430 file actually as a black and white 30 00:01:35,430 --> 00:01:39,030 image. So 0 is a flag is argument, 31 00:01:39,090 --> 00:01:41,760 which implies an image should write as 32 00:01:41,760 --> 00:01:43,890 black and white, in either grayscale 33 00:01:43,890 --> 00:01:46,050 actually, and then we create a variable 34 00:01:46,050 --> 00:01:48,120 where we will store the resized 35 00:01:48,120 --> 00:01:52,950 images, so the image is 100 by 100. So 36 00:01:52,950 --> 00:01:54,570 I'm passing the origin of the image here 37 00:01:54,600 --> 00:01:57,330 and their size, the new size that the 38 00:01:57,330 --> 00:01:59,700 image will get, and then we want to show the 39 00:01:59,700 --> 00:02:03,180 image just for demonstration, it's not 40 00:02:03,180 --> 00:02:05,400 really important, but it lets you check 41 00:02:05,400 --> 00:02:07,320 all the images that are being resized, 42 00:02:08,040 --> 00:02:10,320 and this is the name of the window, and 43 00:02:10,320 --> 00:02:14,520 then I pass here a waitKey method, and 44 00:02:14,520 --> 00:02:17,670 500 means 500 milliseconds. So each 45 00:02:17,670 --> 00:02:20,220 image will show and it will wait for 46 00:02:20,250 --> 00:02:22,920 half a second. So 500 milliseconds, and 47 00:02:22,920 --> 00:02:24,600 then after this half a second, Python 48 00:02:24,600 --> 00:02:26,820 will go to the next line and then to the 49 00:02:26,820 --> 00:02:29,190 next, and then it will go to the next item 50 00:02:29,190 --> 00:02:31,800 of the list and so on. So waitKey 500 51 00:02:31,800 --> 00:02:34,421 milliseconds, and then we have destroyAllWindows 52 00:02:34,445 --> 00:02:37,560 after this time passes, and then 53 00:02:37,560 --> 00:02:41,400 we write the resized_image. So re was 54 00:02:41,400 --> 00:02:44,610 a variable that holds the image object, 55 00:02:44,610 --> 00:02:47,220 the resized_image object, and this here, 56 00:02:47,670 --> 00:02:53,100 all this is a new name of the file. So 57 00:02:53,610 --> 00:02:55,860 what we get here is so we will have 58 00:02:55,860 --> 00:02:58,590 resized in the beginning of the image 59 00:02:58,590 --> 00:03:00,870 name and then just after that we 60 00:03:00,870 --> 00:03:03,570 will have a name of the original image. 61 00:03:04,740 --> 00:03:07,380 So for instance, we would have, for 62 00:03:07,380 --> 00:03:11,821 galaxy, we would have resized galaxy.jpg. 63 00:03:11,845 --> 00:03:15,255 So image here would be galaxy.jpg, 64 00:03:16,535 --> 00:03:18,930 which is this one here, and 65 00:03:18,930 --> 00:03:21,090 yeah, because the script is inside this 66 00:03:21,090 --> 00:03:24,120 folder, this list actually, the image 67 00:03:24,120 --> 00:03:25,980 of the list, would look something like 68 00:03:27,852 --> 00:03:34,140 galaxy.jpg, and then kangaroo, 69 00:03:34,670 --> 00:03:37,390 you know, australia.jpg, and so on. So 70 00:03:37,414 --> 00:03:40,052 [No audio] 71 00:03:40,089 --> 00:03:42,822 this gets the relative paths of the files. 72 00:03:42,870 --> 00:03:45,210 We're not getting the full path. Okay, I 73 00:03:45,210 --> 00:03:48,150 hope that is clear. So resized_galaxy, 74 00:03:48,150 --> 00:03:50,610 we could add underscore so that 75 00:03:50,610 --> 00:03:54,510 we discriminate the resized word from the 76 00:03:54,600 --> 00:04:01,020 other image name. Great, let me execute this 77 00:04:01,457 --> 00:04:02,697 python script. 78 00:04:02,721 --> 00:04:04,932 [No audio] 79 00:04:04,957 --> 00:04:06,990 So half a second, half a 80 00:04:06,990 --> 00:04:11,160 second, and yeah, its done, and let's check the 81 00:04:11,160 --> 00:04:14,670 images. So from here up are the original 82 00:04:14,670 --> 00:04:16,770 images and these are the image products. 83 00:04:17,010 --> 00:04:19,290 So you can see here that all these are 84 00:04:19,290 --> 00:04:22,685 100 by 100, and they are in a grayscale. 85 00:04:22,709 --> 00:04:24,709 [No audio] 86 00:04:24,734 --> 00:04:27,690 Okay, that's it. See you in the next lecture. 87 00:04:27,714 --> 00:04:29,714 [No audio]