What is the primary purpose of the picamera2 library?
The picamera2 library is used to control the Raspberry Pi camera module, allowing you to capture images and videos programmatically.
Click to reveal answer
beginner
How do you start the camera preview using picamera2?
You call the start_preview() method on a Picamera2 object to show the camera preview on the screen.
Click to reveal answer
beginner
Which method captures a still image with picamera2?
The capture_file(filename) method captures a still image and saves it to the specified filename.
Click to reveal answer
beginner
What is the typical first step before capturing images with picamera2?
You create a Picamera2 object and configure it, usually with picam2 = Picamera2() and picam2.configure() before starting the camera.
Click to reveal answer
beginner
How do you stop the camera preview in picamera2?
You call the stop_preview() method on the Picamera2 object to stop showing the camera preview.
Click to reveal answer
What does the Picamera2() command do?
ACreates a new camera object to control the Raspberry Pi camera
BStarts the camera preview automatically
CCaptures an image immediately
DStops the camera preview
✗ Incorrect
The Picamera2() command creates a new camera object but does not start preview or capture automatically.
Which method saves a photo to a file?
Astart_preview()
Bconfigure()
Ccapture_file(filename)
Dstop_preview()
✗ Incorrect
The capture_file(filename) method captures an image and saves it to the given filename.
Before capturing images, what should you do after creating the Picamera2 object?
ACall capture_file() immediately
BCall stop_preview()
CNothing, just start capturing
DCall configure() to set camera settings
✗ Incorrect
You should call configure() to set up camera settings before capturing images.
How do you show the camera preview on the screen?
Astart_preview()
Bcapture_file()
Cconfigure()
Dstop_preview()
✗ Incorrect
The start_preview() method shows the live camera preview on the screen.
What is the correct way to stop the camera preview?
Astart_preview()
Bstop_preview()
Cconfigure()
Dcapture_file()
✗ Incorrect
You stop the preview by calling stop_preview() on the Picamera2 object.
Explain the basic steps to capture a photo using the picamera2 library.
Think about setting up, previewing, capturing, and stopping.
You got /5 concepts.
Describe how to show and stop the camera preview using picamera2.
Preview is like looking through the camera before taking a photo.
You got /2 concepts.
Practice
(1/5)
1. What is the main purpose of the picamera2 library on Raspberry Pi?
easy
A. To control the Raspberry Pi camera for capturing images and videos
B. To manage network connections on Raspberry Pi
C. To program the Raspberry Pi GPIO pins
D. To install software packages on Raspberry Pi
Solution
Step 1: Understand the library's purpose
The picamera2 library is designed specifically to control the Raspberry Pi camera module.
Step 2: Compare options with the library's function
Only To control the Raspberry Pi camera for capturing images and videos correctly describes controlling the camera for images and videos.
Final Answer:
To control the Raspberry Pi camera for capturing images and videos -> Option A
Quick Check:
picamera2 controls camera = B [OK]
Hint: Remember picamera2 is for camera control only [OK]
Common Mistakes:
Confusing picamera2 with network or GPIO libraries
Thinking picamera2 installs software
Assuming picamera2 manages hardware other than camera
2. Which of the following is the correct way to import the picamera2 library in a Python script?
easy
A. from picamera2 import Picamera2
B. from picamera import picamera2
C. import Picamera2
D. import picamera2
Solution
Step 1: Recall correct import syntax for picamera2
The correct class name is Picamera2 and it is imported from the picamera2 module.
Step 2: Check each option's syntax
from picamera2 import Picamera2 uses correct capitalization and syntax: from picamera2 import Picamera2. Others are incorrect due to wrong case or module names.
Final Answer:
from picamera2 import Picamera2 -> Option A
Quick Check:
Correct import = D [OK]
Hint: Remember Python is case-sensitive for imports [OK]
Common Mistakes:
Using wrong capitalization for Picamera2
Importing from 'picamera' instead of 'picamera2'
Trying to import the whole module without class
3. What will the following code print?
from picamera2 import Picamera2
picam2 = Picamera2()
picam2.start()
print(type(picam2))
picam2.stop()
medium
A. Error: Picamera2 not defined
B. <class 'picamera2.Picamera2'>
C. <class 'camera.Picam2'>
D. None
Solution
Step 1: Analyze object creation and type
The code creates an instance of Picamera2 and prints its type, which should be the class picamera2.Picamera2.
Step 2: Check for errors or output
Since the import and instantiation are correct, no error occurs. The printed type matches <class 'picamera2.Picamera2'>.
Final Answer:
<class 'picamera2.Picamera2'> -> Option B
Quick Check:
type(picam2) = <class 'picamera2.Picamera2'> [OK]
Hint: type() shows the object's class with module name [OK]
Common Mistakes:
Expecting a runtime error due to missing start()
Confusing class name or module in output
Thinking print outputs None
4. Identify the error in this code snippet:
from picamera2 import Picamera2
picam2 = Picamera2()
picam2.capture_file('image.jpg')
picam2.stop()
medium
A. No error; code runs fine
B. Wrong method name; should be capture_image()
C. File extension must be .png, not .jpg
D. Missing call to picam2.start() before capture_file
Solution
Step 1: Check method usage order
Before capturing an image, the camera must be started with start(). This code skips that step.
Step 2: Verify method names and file formats
capture_file() is correct method name, and .jpg is a valid extension. So no error there.
Final Answer:
Missing call to picam2.start() before capture_file -> Option D
Quick Check:
start() needed before capture_file() [OK]
Hint: Always start camera before capturing [OK]
Common Mistakes:
Skipping picam2.start() before capture
Assuming capture_file() is incorrect method
Thinking file extension causes error
5. You want to preview the camera feed on screen before capturing a photo using picamera2. Which sequence of commands is correct?
hard
A. picam2 = Picamera2()
picam2.start_preview()
picam2.capture_file('photo.jpg')
picam2.stop()
B. picam2 = Picamera2()
picam2.start()
picam2.preview()
picam2.capture_file('photo.jpg')
picam2.stop()
C. picam2 = Picamera2()
picam2.start()
picam2.start_preview()
picam2.capture_file('photo.jpg')
picam2.stop()
D. picam2 = Picamera2()
picam2.preview()
picam2.capture_file('photo.jpg')
picam2.stop()
Solution
Step 1: Understand preview and start sequence
You must start the camera with start() before previewing. The method to show preview is start_preview().
Step 2: Check each option's command order
picam2 = Picamera2()
picam2.start()
picam2.start_preview()
picam2.capture_file('photo.jpg')
picam2.stop() correctly calls start(), then start_preview(), then captures and stops. Others miss start() or use wrong methods.
Final Answer:
picam2 = Picamera2()
picam2.start()
picam2.start_preview()
picam2.capture_file('photo.jpg')
picam2.stop() -> Option C
Quick Check:
start() then start_preview() = A [OK]
Hint: Always start() before preview or capture [OK]
Common Mistakes:
Calling preview without start()
Using preview() instead of start_preview()
Not stopping camera after use
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.