Bird
0
0

What will the following Python code output when run on a Raspberry Pi with a connected camera?

medium📝 Predict Output Q13 of 15
Raspberry Pi - Camera Module
What will the following Python code output when run on a Raspberry Pi with a connected camera?
import cv2
cap = cv2.VideoCapture(0)
ret, frame = cap.read()
print(ret)
AFalse
BTrue
CNone
DError
Step-by-Step Solution
Solution:
  1. Step 1: Understand cv2.VideoCapture(0)

    This opens the default camera (index 0) on Raspberry Pi.
  2. Step 2: Analyze cap.read() output

    cap.read() returns two values: ret (True if frame captured) and frame (image data).
  3. Final Answer:

    True -> Option B
  4. Quick Check:

    Camera connected and read successful = True [OK]
Quick Trick: ret is True if camera frame is captured [OK]
Common Mistakes:
MISTAKES
  • Assuming ret is the image frame
  • Expecting None if no error
  • Thinking it raises an error without camera

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes