WEBVTT

00:00.170 --> 00:00.650
Great.

00:00.650 --> 00:06.440
The camera is now plugged to the Raspberry Pi, so the hardware setup is done and we can take some photos.

00:06.440 --> 00:10.520
We will start with the terminal and then we will see how to do the same thing with Python.

00:10.520 --> 00:12.260
So you can open a terminal.

00:12.260 --> 00:15.680
And well we are in our home directory.

00:15.680 --> 00:20.780
But what I'm going to do is I'm going to create a new folder here so that we can put the photos inside

00:20.780 --> 00:22.790
this folder and not just anywhere.

00:22.790 --> 00:29.120
So let's create here with mkdir a camera folder for example okay.

00:29.240 --> 00:32.780
And you see now I have my camera folder here.

00:32.810 --> 00:33.290
Great.

00:33.320 --> 00:37.730
Now what is the command that you can use to take a photo from the terminal.

00:37.760 --> 00:41.420
The command is RPI cam and then dash.

00:41.840 --> 00:44.630
Still okay with RPI cam.

00:44.630 --> 00:46.220
Dash still you can take a photo.

00:46.220 --> 00:50.240
Let's run that to see just with no other parameter.

00:51.140 --> 00:52.370
And you're going to see some logs.

00:52.370 --> 00:53.660
It's going to open a preview.

00:53.660 --> 00:55.700
So you see I can say hi.

00:55.820 --> 00:59.000
And the preview is going to be here for about five seconds.

00:59.030 --> 00:59.420
All right.

00:59.420 --> 00:59.960
And that's it.

00:59.960 --> 01:04.160
But this is not going to take a photo actually it's just a preview okay.

01:04.190 --> 01:07.230
So when you run this command it's is going to open a preview.

01:07.230 --> 01:13.710
If you want to save a photo to a file, you will need to do the same command with dash o for output

01:13.710 --> 01:16.110
and then put a file name.

01:16.380 --> 01:18.000
So for example test.

01:18.000 --> 01:22.860
And then we're going to use the JPG extension okay we create a JPEG.

01:22.860 --> 01:27.210
So here the extension is quite important when you create a file for a photo.

01:27.210 --> 01:32.040
And well I'm not just going to create this file here in the home directory okay.

01:32.070 --> 01:34.800
We have just created a camera folder.

01:34.800 --> 01:37.620
So I'm going to put this file inside the camera folder.

01:37.620 --> 01:39.090
And here we have two options.

01:39.090 --> 01:44.610
First I could have just navigated to the camera folder and just run that command.

01:44.610 --> 01:48.450
But I can also provide the path directly here.

01:48.450 --> 01:54.150
So I can do camera slash test dot jpg okay.

01:54.150 --> 01:55.920
Because I'm in my home directory.

01:55.920 --> 01:59.520
So I just need to go to camera first and then I can save the file.

01:59.520 --> 02:01.080
Let's run that again.

02:01.080 --> 02:03.450
And this is going to open the preview.

02:03.480 --> 02:05.760
This is going to take a photo.

02:09.270 --> 02:09.720
All right.

02:09.720 --> 02:11.320
And then exit Now.

02:11.350 --> 02:13.960
Well, let's just open the file manager here.

02:14.500 --> 02:19.000
If I go to my camera folder, I have my test dot jpeg.

02:20.560 --> 02:21.640
Let's open it.

02:21.640 --> 02:24.520
And the first thing you can notice maybe is that.

02:24.520 --> 02:26.410
So this is actually the ceiling.

02:26.410 --> 02:28.900
So the photo is upside down.

02:28.930 --> 02:29.230
All right.

02:29.230 --> 02:32.080
Just because that's where that's how I placed my camera.

02:32.080 --> 02:33.850
So the photo is upside down.

02:33.880 --> 02:37.390
I could just change the position of the camera if I wanted to.

02:37.420 --> 02:40.570
But I'm going to leave it like this and let's see how to fix that.

02:40.570 --> 02:44.830
So first you see we can rotate the image twice like that.

02:44.830 --> 02:47.530
So we can rotate the image by 90 degrees twice.

02:47.530 --> 02:50.920
And the image is correctly placed which you can see.

02:50.920 --> 02:52.630
The door here is on the right.

02:52.660 --> 02:57.910
I'm going to put it back like this just to show you that there is actually another way you can do that.

02:58.030 --> 03:03.880
So if you go on edit, you see you have the rotate, but you can also flip the image.

03:04.240 --> 03:06.700
So we can flip the image vertically.

03:06.700 --> 03:09.340
And well, if you remember the door was on the right.

03:09.340 --> 03:14.500
So if you flip the image vertically you also need to flip the image horizontally.

03:14.500 --> 03:18.330
And then it's like if you do a 180 rotation.

03:18.330 --> 03:23.160
And I showed you this because, well, we have an option in the command line tool.

03:23.160 --> 03:25.920
And I'm also going to be the same option for Python program.

03:25.920 --> 03:27.600
So I'm going to run the same command.

03:27.630 --> 03:32.520
You see I use the up arrow to go back to the previous command.

03:32.790 --> 03:37.290
And then I'm going to do dash dash v flip.

03:37.320 --> 03:37.560
Okay.

03:37.590 --> 03:39.930
So vertical flip and then dash dash.

03:39.930 --> 03:41.340
So with two dashes here okay.

03:41.370 --> 03:45.240
It's quite important H flip for horizontal flip.

03:45.240 --> 03:49.470
And that's going to do exactly what I just did here with the display.

03:49.470 --> 03:51.840
So now I'm going to run this command.

03:52.920 --> 03:53.160
Okay.

03:53.190 --> 03:55.440
It's going to take a photo.

03:56.700 --> 03:59.010
So you see it's stabilizing taking a photo.

03:59.010 --> 04:01.680
And then well the file has been replaced.

04:01.710 --> 04:01.890
Okay.

04:01.920 --> 04:07.560
So if you take a photo and you use the same file name, it's going to replace whatever file was with

04:07.560 --> 04:08.430
the same name.

04:09.210 --> 04:12.660
Now you can see the photo is correctly orientated.

04:12.660 --> 04:13.710
It's not upside down.

04:13.710 --> 04:22.300
And finally what you can do is well you see that the file size is 1.4MB here with that resolution.

04:22.330 --> 04:22.510
Okay.

04:22.540 --> 04:26.800
So this is the resolution actually for the module three of the camera.

04:26.800 --> 04:30.820
If you have the module 1 or 2 the resolution is probably going to be lower.

04:30.820 --> 04:33.400
But still you can see the photo is 1.5MB.

04:33.430 --> 04:34.480
It's not too big.

04:34.480 --> 04:40.000
But then let's say you want to send the photo by email or to send it over the internet.

04:40.030 --> 04:44.260
Well, if we can find an easy way to reduce the size, that's going to be better.

04:44.260 --> 04:47.200
So we can actually lower the resolution.

04:47.200 --> 04:48.670
And I'm going to show you first.

04:48.670 --> 04:51.340
So this is specific to the version three of the camera.

04:51.340 --> 04:56.080
But then I'm going to show you also with the documentation where you can find more information.

04:56.080 --> 04:58.300
So what resolution can we use.

04:58.300 --> 04:59.260
You see that.

04:59.260 --> 05:02.110
So we have some logs here that's quite useful.

05:02.110 --> 05:03.340
This is the resolution.

05:03.340 --> 05:06.520
This is the max resolution for this camera.

05:06.520 --> 05:12.550
And then you can see we also have another mode which is half another mode which is one third okay.

05:12.580 --> 05:17.230
So if you multiply this by three you're going to get exactly those values.

05:17.260 --> 05:17.530
All right.

05:17.560 --> 05:22.840
So what we're going to try to do is to take a photo with that resolution here.

05:22.840 --> 05:31.370
And I would recommend especially for the camera module V3 to use a multiple of those resolutions here.

05:31.370 --> 05:33.290
So that one, that one or that one.

05:33.290 --> 05:34.070
Why is that?

05:34.070 --> 05:39.710
Because if you use something different, the image actually might be cropped in a weird way, or you

05:39.710 --> 05:43.280
might miss a lot of information on the image, you can try by yourself.

05:43.280 --> 05:48.020
But here I'm going to use then this resolution here how to change the resolution.

05:48.020 --> 05:51.170
So I'm going to use the up arrow with the same command.

05:51.170 --> 05:54.260
And then I'm going to use dash dash width.

05:54.290 --> 05:59.840
The width is going to be so width and then space 1536.

05:59.840 --> 06:08.060
And then another option dash dash height with this time is going to be 864.

06:08.210 --> 06:08.450
Okay.

06:08.450 --> 06:11.360
So you see we have the dash o option for the output.

06:11.360 --> 06:17.780
And then with two dashes we have vertical flip horizontal flip width and height.

06:17.780 --> 06:22.220
I'm going to press enter okay.

06:22.250 --> 06:23.330
It's going to take a photo.

06:23.330 --> 06:25.370
So the preview and then the photo.

06:26.030 --> 06:26.630
Great.

06:26.630 --> 06:28.430
I go back to my file.

06:28.460 --> 06:33.640
You see the photo is well as you can see it has been zoomed a bit.

06:33.640 --> 06:35.980
So if you remember we could see the shelf here.

06:36.010 --> 06:39.490
Okay, so for that you may experiment with different resolutions.

06:39.520 --> 06:39.760
Okay.

06:39.790 --> 06:42.430
Here I'm going to keep that one which is good enough.

06:42.430 --> 06:46.660
And you can see now the file is about 200 something kilobytes.

06:46.660 --> 06:47.770
So that's much smaller.

06:47.800 --> 06:49.000
That's more than six.

06:49.030 --> 06:50.710
That's about six times smaller.

06:50.890 --> 06:56.680
So that's quite good because let's say you want to take photos and store them on your SD card.

06:56.680 --> 07:01.360
And you want to take a photo every, let's say, one minute and store them for several days.

07:01.360 --> 07:07.000
Then if the image can be six times smaller, that's going to be much better for you to handle that.

07:07.000 --> 07:09.370
But well, that's going to depend on your application.

07:09.370 --> 07:12.310
Maybe you need a higher resolution, maybe a lower resolution.

07:12.490 --> 07:14.080
That's going to depend every time.

07:14.080 --> 07:17.350
Now to know which resolution you can use anyway.

07:17.350 --> 07:19.630
You're going to use that command here okay.

07:19.660 --> 07:21.340
It's going to be the same for everybody.

07:21.370 --> 07:27.730
But then you can just go on, open a web browser and you type Raspberry Pi camera documentation, and

07:27.730 --> 07:30.010
you're going to get to the documentation here.

07:30.280 --> 07:33.370
So you can see the URL here.

07:33.400 --> 07:35.830
Raspberry pi.com/documentation.

07:35.830 --> 07:37.220
Slash Accessories.

07:37.520 --> 07:38.330
Cameras.

07:38.600 --> 07:39.470
HTML.

07:39.890 --> 07:41.120
The URL might change.

07:41.120 --> 07:46.370
That's why I recommend you that you search it on Google and you should get to a page like this.

07:46.400 --> 07:46.700
Okay.

07:46.730 --> 07:47.750
And you can go down.

07:47.750 --> 07:52.700
So basically you have lots of information about the different camera modules you see about the cable

07:52.730 --> 07:53.750
etc..

07:53.840 --> 07:58.700
And here that's what's interesting for us now.

07:58.790 --> 08:02.870
It's the hardware specification for the different camera modules.

08:02.870 --> 08:05.150
So the v1 here v2 and v3.

08:05.150 --> 08:10.550
So as I told you the main difference is going to be on the resolution here we have five megapixels and

08:10.550 --> 08:12.860
then eight and then 11.9.

08:12.980 --> 08:18.080
And the sensor resolution here you see that's the one.

08:18.080 --> 08:20.600
So that's the default one that we have used.

08:20.660 --> 08:23.480
Then we used the third of that resolution.

08:23.480 --> 08:27.560
But you can see for the V2 for example it's a different resolution.

08:27.560 --> 08:32.480
So depending on that value you might try to use something different.

08:32.480 --> 08:34.370
And you might need to experiment a bit.

08:34.400 --> 08:38.900
Try to find a resolution that both looks good okay.

08:38.930 --> 08:40.880
That doesn't crop the image too much.

08:40.880 --> 08:42.890
And that is also not too big.
