Challenge - 5 Problems
Picamera2 Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this Picamera2 preview code?
Consider this Python code using the picamera2 library on a Raspberry Pi. What will it print when run?
Raspberry Pi
from picamera2 import Picamera2 picam2 = Picamera2() picam2.start_preview() print('Preview started')
Attempts:
2 left
💡 Hint
The start_preview() method starts the camera preview and does not block the program.
✗ Incorrect
The code initializes the camera and starts the preview. Then it prints 'Preview started'. No errors occur.
❓ Predict Output
intermediate2:00remaining
What does this code print after capturing an image?
This code captures an image and prints the type of the image data. What is printed?
Raspberry Pi
from picamera2 import Picamera2 picam2 = Picamera2() picam2.start() image = picam2.capture_array() print(type(image))
Attempts:
2 left
💡 Hint
capture_array() returns image data as a numpy array.
✗ Incorrect
The capture_array() method returns the image as a numpy array, so printing its type shows .
🔧 Debug
advanced2:00remaining
Why does this Picamera2 code raise an error?
This code tries to capture an image without starting the camera. What error will it raise?
Raspberry Pi
from picamera2 import Picamera2 picam2 = Picamera2() image = picam2.capture_array() print('Captured')
Attempts:
2 left
💡 Hint
You must start the camera before capturing images.
✗ Incorrect
Calling capture_array() before starting the camera causes a RuntimeError because the camera hardware is not active.
🧠 Conceptual
advanced2:00remaining
What is the purpose of the Picamera2.start_preview() method?
Choose the best description of what start_preview() does in the picamera2 library.
Attempts:
2 left
💡 Hint
Think about what 'preview' means in a camera context.
✗ Incorrect
start_preview() opens a window or display area showing the live camera feed so you can see what the camera sees.
❓ Predict Output
expert2:00remaining
What is the output of this Picamera2 exposure mode code?
This code sets the exposure mode and prints the current mode. What will it print?
Raspberry Pi
from picamera2 import Picamera2 picam2 = Picamera2() picam2.start() picam2.set_controls({'ExposureMode': 1}) print(picam2.controls.get('ExposureMode', 'default'))
Attempts:
2 left
💡 Hint
set_controls() changes camera settings; controls is a dictionary of current settings.
✗ Incorrect
After setting ExposureMode to 1 ('night'), reading it from controls returns 1.
