The Raspberry Pi camera module (Pi Cam) was launched in May 2013. Its first released version is equipped with a 5 million pixel sensor, which is connected to the CSI interface on the Raspberry Pi through a cable. The second release version of Pi Cam, also called Pi NoIR, is equipped with the same sensor but without infrared filter. Therefore, the second version of the camera module is like a security surveillance camera, which can observe the wavelength of the near infrared (700–1000 nm), but of course it also sacrifices a certain color rendering.
This article will show how to install the camera module on the Raspberry Pi . We will use the first version of the camera module to demonstrate. After installing the camera module, you will use three applications to access this module: raspistill, raspiyuv and raspivid. The first two applications are used to capture images, and the third application is to capture videos. The raspistill tool generates standard picture files, such as .jpg images, while raspiyuv can generate unprocessed raw image files through the camera.
1. Install the Raspberry Pi camera module
(I have already installed it for the students in advance. If there is a problem with the camera after debugging, you can try to plug it in.
Note: The Raspberry Pi must be turned off and power off before plugging or unplugging, otherwise the camera may be burned out)
Follow the steps below to connect the Raspberry Pi camera module to the Raspberry Pi:
1. Find the CSI (Camera Serial Interface) interface (the CSI interface is next to the Ethernet interface), and lift the dark tape.
2. Pull up the CSI interface baffle.
3. Take up your camera module and tear off the plastic protective film attached to the lens. Make sure that the yellow part of the PCB (the side with words) is installed perfectly (you can lightly press the yellow part to ensure perfect installation).
4. Insert the flat cable into the CSI interface. Remember, the side with the blue tape should face the Ethernet interface. Similarly, at this time, after confirming that the cable is installed, pull down the baffle.
Finished photo after installing the camera module:
Okay, now your Pi Cam is ready to take photos or videos.
2. Enable the camera module on the Raspberry Pi
1. After installing the camera module, first confirm that you have upgraded the Raspberry Pi system and applied the latest firmware. You can enter the following commands to operate:
(It takes a long time for the first update, please be patient, you can choose to take a look at the relevant documents to facilitate the next experiment)
2. Run the Raspberry Pi configuration tool to activate the camera module:
$ sudo raspi-config
Move the cursor to “Enable Camera” in the menu and set it to Enable. Restart the Raspberry Pi after completion.
Then press “Esc” on the keyboard to exit, and then enter “init 6” or “reboot” in the command line to restart the Raspberry Pi.
Three, take pictures through the camera module
After restarting the Raspberry Pi, we can use Pi Cam. To use it to take photos, you can run raspistill from the command line:
$ raspistill -o keychain.jpg -t 2000
This command will take a photo after 2000ms and save it as keychain.jpg. Below is a keychain of my bear doll taken by Pi Cam.
The usage of the raspiyuv tool is similar, except that the shot obtained is an unprocessed raw image.
Take video through camera module
If you want to take a video with the camera module, you can run the raspivid tool from the command line. The following command will shoot a video according to the default configuration (length 5 seconds, resolution 1920x1080, bit rate 17Mbps).
$ raspivid -o mykeychain.h264
If you want to change the shooting duration, just use the “-t” option to set the length you want (the unit is milliseconds).
$ raspivid -o mykeychain.h264 -t 10000
Use the “-w” and “-h” options to reduce the resolution to 1280x720…
$ raspivid -o mykeychain.h264 -t 10000 -w 1280 -h 720
The output of raspivid is an uncompressed H.264 video stream, and this video contains no sound. In order to be played by normal video players, the raw H.264 video needs to be converted. You can use the MP4Box application included in the gpac package.
To install gpac on Raspbian, enter the command:
$ sudo apt-get install -y gpac
Then convert this raw H.264 format video stream into 30 frames per second .mp4 format video:
$ MP4Box -fps 30 -add keychain.h264 keychain.mp4