Consider this Python code snippet using the picamera library to capture an image. What will it print?
import picamera from time import sleep with picamera.PiCamera() as camera: camera.resolution = (640, 480) camera.start_preview() sleep(2) camera.capture('/home/pi/image.jpg') print('Image captured at resolution:', camera.resolution)
Check the resolution set before capture.
The code sets the camera resolution to (640, 480) before capturing. The print statement outputs this resolution.
To use the Raspberry Pi camera module, you must enable the camera interface. Which command correctly enables it?
Think about the Raspberry Pi configuration tool.
The camera interface is enabled via sudo raspi-config under Interface Options > Camera.
Look at this code snippet. It raises an error when run. What is the cause?
import picamera camera = picamera.PiCamera() camera.capture('test.jpg') camera.close()
Consider resource management and proper closing of the camera.
Not using a with statement or properly closing the camera can cause errors. Here, camera.close() is called, but if an exception occurs before, the camera may not close properly. Using with ensures proper cleanup.
Choose the code snippet that correctly sets the resolution to 1280x720 and captures an image named 'photo.jpg'.
Check the correct attribute name and data type for resolution.
The resolution attribute expects a tuple like (1280, 720). Option A uses this correctly. Option A uses a non-existent method. Option A misses closing the camera properly in a with block. Option A uses a list instead of a tuple, which is invalid.
This code captures 5 images in a burst with 1 second delay between each. How many image files will be saved?
import picamera from time import sleep with picamera.PiCamera() as camera: camera.resolution = (640, 480) for i in range(5): camera.capture(f'/home/pi/image_{i}.jpg') sleep(1)
Count how many times the capture method is called in the loop.
The loop runs 5 times, capturing and saving an image each time with a unique filename. So, 5 images are saved.
