Bird
0
0

What will be the output of this code snippet when run on a Raspberry Pi with a camera connected?

medium📝 Predict Output Q13 of 15
Raspberry Pi - Camera Module
What will be the output of this code snippet when run on a Raspberry Pi with a camera connected?
from picamera import PiCamera
from time import sleep
camera = PiCamera()
camera.start_preview()
sleep(2)
camera.capture('/home/pi/image.jpg')
camera.stop_preview()
AThe program throws an error because sleep is too short
BThe camera preview shows for 2 seconds, then saves image.jpg
CNo image is saved because stop_preview() is called too early
DThe preview never starts because start_preview() is missing
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the preview and sleep timing

    The preview starts, then the program waits 2 seconds allowing the camera to adjust.
  2. Step 2: Capture and save the image after preview

    After waiting, the image is captured and saved to '/home/pi/image.jpg', then preview stops.
  3. Final Answer:

    The camera preview shows for 2 seconds, then saves image.jpg -> Option B
  4. Quick Check:

    Preview + sleep + capture = A [OK]
Quick Trick: Preview then sleep before capture ensures good image [OK]
Common Mistakes:
MISTAKES
  • Assuming sleep is too short causes error
  • Thinking stop_preview() prevents saving
  • Believing start_preview() is missing

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes