Читать книгу Raspberry Pi For Dummies - McManus Sean, Evans Jonathan, Sean McManus - Страница 40
Testing the Camera Module
ОглавлениеLet’s test whether your camera is working correctly.
Make sure the camera is enabled: Go into the Raspberry Pi Configuration tool, click Interfaces, and select Enabled beside the Camera option. For more information, see the “Configuring Your Raspberry Pi in Raspberry Pi OS” section, earlier in this chapter. You’ll need to reboot after enabling the camera.
We’ll test the camera from the command line interface, which is covered in more depth in Chapter 5. Click the Terminal icon at the top of the screen to start. It has a >_
symbol on it. To take a still photo, type in this command:
raspistill -o testshot.jpg
You should see what the camera sees onscreen for a moment before it takes the photo. The picture is saved with the filename testshot.jpg
. You can verify that the image was created by looking at the files in your directory with this command:
ls
You can use lots of different options to take still photos, too. This example takes a shot with the pastel filter and flips the picture horizontally (-hf
) and vertically (-vf
):
raspistill -ifx pastel -hf -vf -o testshot2.jpg
All those hyphens and letter combinations might seem a bit random to you now, but after you read Chapter 5, they should make more sense. To see the documentation for raspistill
, type
raspistill | less
Use the down-arrow key to move through the information, and press Q to finish.
Your photos are stored in your pi
directory. See Chapter 4 for instructions on how to use File Manager to find your files and Image Viewer to see them.
To shoot video, you use raspivid
. Enter this command to shoot a 5-second film:
raspivid -o testvideo.h264 -t 5000
The video is saved with the filename testvideo.h264
and is 5000 milliseconds (5 seconds) long. You can view the video you made using
omxplayer testvideo.h264
The video footage is captured as a raw H264 video stream. For greater compatibility with media players, it's a good idea to convert it to an MP4 file. Start by installing MP4Box using this command:
sudo apt install gpac
Then you can convert your video file (called testvideo.h264
) into an MP4 file (called testvideo.mp4
) like this:
MP4Box -add testvideo.h264 testvideo.mp4
You can get help on using raspivid
with
raspivid | less
There is also a library called picamera that you can use in Python to access the camera from your own Python programs. By adding the Video Sensing extension in Scratch, you can use the camera to make onscreen characters react to movement in the video.
For more information on using the Raspberry Pi Camera Module, see the documentation at www.raspberrypi.org/documentation/usage/camera
.