Great.
The camera is now plugged to the Raspberry Pi, so the hardware setup is done and we can take some photos.
We will start with the terminal and then we will see how to do the same thing with Python.
So you can open a terminal.
And well we are in our home directory.
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
this folder and not just anywhere.
So let's create here with mkdir a camera folder for example okay.
And you see now I have my camera folder here.
Great.
Now what is the command that you can use to take a photo from the terminal.
The command is RPI cam and then dash.
Still okay with RPI cam.
Dash still you can take a photo.
Let's run that to see just with no other parameter.
And you're going to see some logs.
It's going to open a preview.
So you see I can say hi.
And the preview is going to be here for about five seconds.
All right.
And that's it.
But this is not going to take a photo actually it's just a preview okay.
So when you run this command it's is going to open a preview.
If you want to save a photo to a file, you will need to do the same command with dash o for output
and then put a file name.
So for example test.
And then we're going to use the JPG extension okay we create a JPEG.
So here the extension is quite important when you create a file for a photo.
And well I'm not just going to create this file here in the home directory okay.
We have just created a camera folder.
So I'm going to put this file inside the camera folder.
And here we have two options.
First I could have just navigated to the camera folder and just run that command.
But I can also provide the path directly here.
So I can do camera slash test dot jpg okay.
Because I'm in my home directory.
So I just need to go to camera first and then I can save the file.
Let's run that again.
And this is going to open the preview.
This is going to take a photo.
All right.
And then exit Now.
Well, let's just open the file manager here.
If I go to my camera folder, I have my test dot jpeg.
Let's open it.
And the first thing you can notice maybe is that.
So this is actually the ceiling.
So the photo is upside down.
All right.
Just because that's where that's how I placed my camera.
So the photo is upside down.
I could just change the position of the camera if I wanted to.
But I'm going to leave it like this and let's see how to fix that.
So first you see we can rotate the image twice like that.
So we can rotate the image by 90 degrees twice.
And the image is correctly placed which you can see.
The door here is on the right.
I'm going to put it back like this just to show you that there is actually another way you can do that.
So if you go on edit, you see you have the rotate, but you can also flip the image.
So we can flip the image vertically.
And well, if you remember the door was on the right.
So if you flip the image vertically you also need to flip the image horizontally.
And then it's like if you do a 180 rotation.
And I showed you this because, well, we have an option in the command line tool.
And I'm also going to be the same option for Python program.
So I'm going to run the same command.
You see I use the up arrow to go back to the previous command.
And then I'm going to do dash dash v flip.
Okay.
So vertical flip and then dash dash.
So with two dashes here okay.
It's quite important H flip for horizontal flip.
And that's going to do exactly what I just did here with the display.
So now I'm going to run this command.
Okay.
It's going to take a photo.
So you see it's stabilizing taking a photo.
And then well the file has been replaced.
Okay.
So if you take a photo and you use the same file name, it's going to replace whatever file was with
the same name.
Now you can see the photo is correctly orientated.
It's not upside down.
And finally what you can do is well you see that the file size is 1.4MB here with that resolution.
Okay.
So this is the resolution actually for the module three of the camera.
If you have the module 1 or 2 the resolution is probably going to be lower.
But still you can see the photo is 1.5MB.
It's not too big.
But then let's say you want to send the photo by email or to send it over the internet.
Well, if we can find an easy way to reduce the size, that's going to be better.
So we can actually lower the resolution.
And I'm going to show you first.
So this is specific to the version three of the camera.
But then I'm going to show you also with the documentation where you can find more information.
So what resolution can we use.
You see that.
So we have some logs here that's quite useful.
This is the resolution.
This is the max resolution for this camera.
And then you can see we also have another mode which is half another mode which is one third okay.
So if you multiply this by three you're going to get exactly those values.
All right.
So what we're going to try to do is to take a photo with that resolution here.
And I would recommend especially for the camera module V3 to use a multiple of those resolutions here.
So that one, that one or that one.
Why is that?
Because if you use something different, the image actually might be cropped in a weird way, or you
might miss a lot of information on the image, you can try by yourself.
But here I'm going to use then this resolution here how to change the resolution.
So I'm going to use the up arrow with the same command.
And then I'm going to use dash dash width.
The width is going to be so width and then space 1536.
And then another option dash dash height with this time is going to be 864.
Okay.
So you see we have the dash o option for the output.
And then with two dashes we have vertical flip horizontal flip width and height.
I'm going to press enter okay.
It's going to take a photo.
So the preview and then the photo.
Great.
I go back to my file.
You see the photo is well as you can see it has been zoomed a bit.
So if you remember we could see the shelf here.
Okay, so for that you may experiment with different resolutions.
Okay.
Here I'm going to keep that one which is good enough.
And you can see now the file is about 200 something kilobytes.
So that's much smaller.
That's more than six.
That's about six times smaller.
So that's quite good because let's say you want to take photos and store them on your SD card.
And you want to take a photo every, let's say, one minute and store them for several days.
Then if the image can be six times smaller, that's going to be much better for you to handle that.
But well, that's going to depend on your application.
Maybe you need a higher resolution, maybe a lower resolution.
That's going to depend every time.
Now to know which resolution you can use anyway.
You're going to use that command here okay.
It's going to be the same for everybody.
But then you can just go on, open a web browser and you type Raspberry Pi camera documentation, and
you're going to get to the documentation here.
So you can see the URL here.
Raspberry pi.com/documentation.
Slash Accessories.
Cameras.
HTML.
The URL might change.
That's why I recommend you that you search it on Google and you should get to a page like this.
Okay.
And you can go down.
So basically you have lots of information about the different camera modules you see about the cable
etc..
And here that's what's interesting for us now.
It's the hardware specification for the different camera modules.
So the v1 here v2 and v3.
So as I told you the main difference is going to be on the resolution here we have five megapixels and
then eight and then 11.9.
And the sensor resolution here you see that's the one.
So that's the default one that we have used.
Then we used the third of that resolution.
But you can see for the V2 for example it's a different resolution.
So depending on that value you might try to use something different.
And you might need to experiment a bit.
Try to find a resolution that both looks good okay.
That doesn't crop the image too much.
And that is also not too big.