Bird
0
0
Raspberry Piprogramming~20 mins

picamera2 library basics in Raspberry Pi - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Picamera2 Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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')
APreview started
BError: start_preview() is not a function
CNothing is printed
DPreview started\nCamera error
Attempts:
2 left
💡 Hint
The start_preview() method starts the camera preview and does not block the program.
Predict Output
intermediate
2: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))
A<class 'bytes'>
B<class 'numpy.ndarray'>
C<class 'PIL.Image.Image'>
DError: capture_array() not found
Attempts:
2 left
💡 Hint
capture_array() returns image data as a numpy array.
🔧 Debug
advanced
2: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')
ARuntimeError: Camera not started
BAttributeError: 'Picamera2' object has no attribute 'capture_array'
CSyntaxError: missing parentheses
DNo error, prints 'Captured'
Attempts:
2 left
💡 Hint
You must start the camera before capturing images.
🧠 Conceptual
advanced
2:00remaining
What is the purpose of the Picamera2.start_preview() method?
Choose the best description of what start_preview() does in the picamera2 library.
AIt stops the camera preview and releases resources.
BIt captures a still image and saves it to disk.
CIt initializes the camera hardware but does not show anything.
DIt starts showing a live camera preview on the screen.
Attempts:
2 left
💡 Hint
Think about what 'preview' means in a camera context.
Predict Output
expert
2: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'))
AError: set_controls() not supported
Bdefault
C1
DNone
Attempts:
2 left
💡 Hint
set_controls() changes camera settings; controls is a dictionary of current settings.