1
00:00:00,330 --> 00:00:08,189
High in this image processing section, we will be using open S.U.V. a lot now, obviously vis a Python

2
00:00:08,189 --> 00:00:17,940
library that is used for computer vision, which includes image processing, capturing video, detecting

3
00:00:17,970 --> 00:00:21,390
objects in images and in video as well.

4
00:00:21,960 --> 00:00:29,660
So in this section, we will focus on image processing and we can do image processing with open CV that

5
00:00:29,670 --> 00:00:31,330
fall in this video.

6
00:00:31,350 --> 00:00:33,720
I will introduce you to over.

7
00:00:34,440 --> 00:00:42,810
And we will write a simple script which converts color JPEG images to grayscale JPEG images.

8
00:00:42,990 --> 00:00:44,550
So let's create a ripple for that.

9
00:00:49,520 --> 00:00:53,860
Convert image to Grayscale.

10
00:00:59,290 --> 00:01:04,180
I'm going to use the shell now to explain some things about open sea.

11
00:01:04,810 --> 00:01:13,510
So obviously we can be imported as CV two, not as open CV, but you'll get an error because we have

12
00:01:13,510 --> 00:01:14,380
to install it.

13
00:01:14,410 --> 00:01:18,220
So good packages and search for open CV.

14
00:01:18,700 --> 00:01:27,700
So you install it as open V-Bucks, you use it as CV to search for open CV Python and that's it's open

15
00:01:27,700 --> 00:01:33,550
CV bash, python press on the plus bottom and the way to bid.

16
00:01:38,580 --> 00:01:42,360
No open CV is based on Nampai.

17
00:01:43,800 --> 00:01:51,360
And Non-poor is a library, a Python library used for numerical calculations, so you have this mattresses

18
00:01:52,140 --> 00:01:57,390
sort of to the 3D mattresses, columns and rows with numbers.

19
00:01:57,720 --> 00:02:07,020
And when you think of an image, an image is made of pixels, but each pixel is associated with a value

20
00:02:07,020 --> 00:02:10,650
a number from zero to 255.

21
00:02:11,130 --> 00:02:19,800
So basically, if an image looks like this and it is made of pixels, let's say this is a small image

22
00:02:20,220 --> 00:02:25,440
made of one two three four five columns.

23
00:02:30,630 --> 00:02:37,170
And for heroes now, each of these will be a pixel with a particular color.

24
00:02:37,410 --> 00:02:37,830
Right?

25
00:02:38,670 --> 00:02:40,110
They will have different colors.

26
00:02:41,280 --> 00:02:46,860
What that means is that each color is associated with a number, actually.

27
00:02:47,190 --> 00:02:50,880
For example, let's say this would be thirty four.

28
00:02:51,180 --> 00:02:53,400
This would be seventy seven.

29
00:02:53,940 --> 00:02:56,940
We would have a maximum of 255.

30
00:02:56,940 --> 00:02:58,830
Not more than that.

31
00:02:59,310 --> 00:03:08,400
But actually an image is not made of one metrics only, but it's made of.

32
00:03:09,820 --> 00:03:11,050
Three mattresses.

33
00:03:11,230 --> 00:03:12,490
So that's times three.

34
00:03:12,640 --> 00:03:19,570
And actually, each color is represented by a triple of numbers.

35
00:03:19,750 --> 00:03:24,610
Well, let's say this purple here would be represented by 65.

36
00:03:24,640 --> 00:03:31,240
I'm just guessing here 127 and 254.

37
00:03:31,270 --> 00:03:31,600
Right.

38
00:03:31,870 --> 00:03:32,680
This is purple.

39
00:03:32,800 --> 00:03:38,630
If we had another thing like yellow, it would be another triple of numbers and so on.

40
00:03:38,650 --> 00:03:43,060
So every color is represented by these by different numbers.

41
00:03:43,330 --> 00:03:45,790
But what does each number mean?

42
00:03:46,240 --> 00:03:49,870
Well, the first one is usually the amount of red.

43
00:03:50,080 --> 00:03:54,130
So 67 means 67 units of red.

44
00:03:54,460 --> 00:03:57,220
And then we'll have green.

45
00:03:57,230 --> 00:04:04,300
So let's say 127 units of green and 254 units of blue.

46
00:04:04,690 --> 00:04:10,880
So our G B, although different systems could also change the order.

47
00:04:10,910 --> 00:04:21,220
So BGR or G B and so the combination of different amounts of red, green and blue ought to make a particular

48
00:04:21,399 --> 00:04:22,000
color.

49
00:04:22,540 --> 00:04:31,240
So to follow this example, we would have like three images stacked together, three mattresses stacked

50
00:04:31,240 --> 00:04:31,750
together.

51
00:04:32,140 --> 00:04:35,890
And so each first pixel.

52
00:04:36,070 --> 00:04:42,520
So this first pixel of the second image here and that first pixel of that second image would represent,

53
00:04:42,520 --> 00:04:44,320
let's see purple.

54
00:04:44,530 --> 00:04:50,590
So purple would be represented by the first number here, 34 or 75.

55
00:04:51,220 --> 00:04:55,270
And the second number in this matrix here and the third number in that matrix.

56
00:04:55,360 --> 00:05:02,620
So stacking those three mattresses together makes up an image right back to our code now.

57
00:05:02,860 --> 00:05:06,160
So installation of open sea view was completed.

58
00:05:06,160 --> 00:05:16,150
So let me reload this page because it's frozen, apparently, and let me control out to clear the terminal,

59
00:05:16,150 --> 00:05:19,660
the shell and then to import CV two.

60
00:05:20,350 --> 00:05:21,820
And this time it's worked.

61
00:05:22,300 --> 00:05:30,040
So if you do dear CV two, you're going to see a range of methods so that you can apply.

62
00:05:30,430 --> 00:05:38,410
For example, with CV to dot rectangle, you can draw a rectangle on an image, jpg image or PNG image,

63
00:05:38,410 --> 00:05:46,530
etc. In this video, we're going to use this methods I'm reads, which means image Freed's.

64
00:05:46,810 --> 00:05:51,080
So we're going to reads an image now to move forward with this video.

65
00:05:51,310 --> 00:05:55,940
You need to have a JPEG image here or PNG or JPEG.

66
00:05:56,110 --> 00:06:04,300
So for convenience, you can download the Galaxy Daypack image from this lecture resources and then

67
00:06:04,300 --> 00:06:05,830
drag and drop it in here.

68
00:06:05,830 --> 00:06:08,870
So I just did that, and this image looks like this.

69
00:06:08,870 --> 00:06:10,120
So it's a color image.

70
00:06:10,600 --> 00:06:15,670
And so now if you go to Maine, those are new import CV too.

71
00:06:16,330 --> 00:06:27,490
And then if you create a variable such as color and say, See two dots, I am reads for image read and

72
00:06:27,490 --> 00:06:36,790
provide the path to the image, which is Galaxy J Pack in this case and set one as a flag, which means

73
00:06:37,010 --> 00:06:39,880
load the image in colors.

74
00:06:40,090 --> 00:06:44,710
So if you wanted to get a grayscale, you'd say zero one means get the color version.

75
00:06:45,550 --> 00:06:47,110
If a print color.

76
00:06:49,100 --> 00:06:50,990
This is what we're going to get.

77
00:06:51,380 --> 00:06:57,140
So it starts from here and you see this three one two three square brackets.

78
00:06:57,680 --> 00:07:02,000
That means we're looking at three mattresses.

79
00:07:02,270 --> 00:07:10,700
So basically, it's a complex structure because you have nested lists and it's actually a non-point

80
00:07:10,700 --> 00:07:11,180
array.

81
00:07:11,210 --> 00:07:12,260
That's how it's called.

82
00:07:12,680 --> 00:07:19,130
But basically, what we have here is those three layers of mattresses that I explained to you earlier.

83
00:07:19,490 --> 00:07:26,270
And these three mattresses have the same dimension because it's one image, but with three mattresses

84
00:07:26,450 --> 00:07:28,100
representing each pixel.

85
00:07:28,520 --> 00:07:34,820
So if you want to see the number of dimensions, actually you could do print colored dots and dim.

86
00:07:36,030 --> 00:07:37,230
So three.

87
00:07:38,250 --> 00:07:46,200
And lastly, let me print out the type of this object just to convince you that this is actually a non-point

88
00:07:46,200 --> 00:07:46,680
array.

89
00:07:46,770 --> 00:07:51,880
So non-point and which means Andy and dimensional, right?

90
00:07:51,960 --> 00:07:53,240
It could have one dimension.

91
00:07:53,250 --> 00:07:54,060
It's got the two.

92
00:07:54,240 --> 00:07:56,160
In this case, it has three dimensions.

93
00:07:56,430 --> 00:07:56,820
Right?

94
00:07:57,270 --> 00:08:00,210
So our purpose was to convert this into grayscale.

95
00:08:00,480 --> 00:08:04,260
To do that, we need to load this as a grayscale image.

96
00:08:04,680 --> 00:08:07,210
And so you have to do with two dots.

97
00:08:07,230 --> 00:08:09,180
I am right.

98
00:08:09,690 --> 00:08:16,560
So another method of CV to to write an image, and you should provide a path to the new image.

99
00:08:16,830 --> 00:08:18,890
Galaxy Grade does J.

100
00:08:19,710 --> 00:08:23,740
And also, what do you want to write in that path?

101
00:08:23,760 --> 00:08:25,170
What's Nampai array?

102
00:08:25,380 --> 00:08:27,390
Well, this one color.

103
00:08:29,040 --> 00:08:30,120
So we're on that.

104
00:08:31,660 --> 00:08:37,690
And you see that a new image is generated, your converts and you'll see that it's in Grayscale.

105
00:08:38,380 --> 00:08:39,669
And that's her script.

106
00:08:40,419 --> 00:08:46,480
This was just a small program just to introduce you to Nampai and open CV.

107
00:08:46,510 --> 00:08:51,790
Next, we're going to dive deeper and do some more complex image processing.

108
00:08:52,230 --> 00:08:53,020
Let's get started.

