Chapter 8 The Raspberry Pi Camera Module 201
THE OFFICIAL RASPBERRY PI BEGINNER’S GUIDE
5 Figure 8-7: A full-screen live preview of the camera view
If your preview was the wrong way up, you can rotate the image to get it the right way up
again. Just under the line camera = PiCamera(), type:
camera.rotation = 180
If the preview was upside-down, that line will get things looking right again. As with raspistill,
camera.rotation lets you rotate the image by 90, 180, or 270 degrees, depending on
whether the cable is coming out of the right, top, or left side of the Camera Module. Remember
to use camera.rotation at the start of any program you write, to avoid capturing images or
video that are the wrong way up!
Capturing still pictures
To capture a picture, rather than just show a live preview, your program needs to be changed.
Start by reducing the delay for the preview: find the sleep(10) line, and change it to read:
sleep( 5 )
Directly under that line, add the following:
camera.capture('/home/pi/Desktop/image.jpg')
TIME TO ADJUST
When the camera is in preview mode, it analyses the video to see
if it needs to adjust its settings to get the best quality. You’ll see this if
you’re in a very dark or very light environment, with the preview at first
being impossible to see, then quickly getting clearer. To give the camera
time to adjust, always add at least a 2-second preview period to your
program before capturing an image.