0
0
Drone Programmingprogramming~20 mins

Camera stream access with OpenCV in Drone Programming - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
OpenCV Camera Master
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 OpenCV camera stream code?

Consider this Python code snippet using OpenCV to access a camera stream. What will it print when run on a system with a working camera?

Drone Programming
import cv2
cap = cv2.VideoCapture(0)
ret, frame = cap.read()
print(ret)
cap.release()
ATrue
BFalse
CNone
DRaises an exception
Attempts:
2 left
💡 Hint

The ret variable tells if the frame was captured successfully.

🧠 Conceptual
intermediate
1:30remaining
Which OpenCV method releases the camera resource?

When you finish using a camera stream in OpenCV, which method should you call to free the camera for other programs?

Acap.stop()
Bcap.close()
Ccap.release()
Dcv2.destroyAllWindows()
Attempts:
2 left
💡 Hint

Think about the method that frees hardware resources.

🔧 Debug
advanced
2:30remaining
Why does this OpenCV code fail to show the camera stream window?

Look at this code snippet. It does not display the camera stream window as expected. What is the reason?

Drone Programming
import cv2
cap = cv2.VideoCapture(0)
ret, frame = cap.read()
if ret:
    cv2.imshow('Camera', frame)
cap.release()
AMissing cv2.waitKey() call to process window events
BIncorrect camera index in VideoCapture
CFrame is None because cap.read() failed
Dcv2.imshow() requires a second argument with window size
Attempts:
2 left
💡 Hint

OpenCV windows need event processing to appear and refresh.

📝 Syntax
advanced
1:30remaining
Which option correctly opens a camera stream and reads a frame in OpenCV?

Choose the code snippet that correctly opens the default camera and reads one frame.

A
cap = cv2.VideoCapture(0)
frame, ret = cap.read()
B
cap = cv2.VideoCapture(0)
ret, frame = cap.read()
C
cap = cv2.VideoCapture()
ret, frame = cap.read(0)
D
cap = cv2.VideoCapture(0)
ret = cap.read(frame)
Attempts:
2 left
💡 Hint

Remember the order of returned values from cap.read().

🚀 Application
expert
3:00remaining
How many frames will this OpenCV loop capture before stopping?

Analyze this code that captures frames from a camera and stops after 5 frames. How many frames does it actually capture?

Drone Programming
import cv2
cap = cv2.VideoCapture(0)
count = 0
while count < 5:
    ret, frame = cap.read()
    if not ret:
        break
    count += 1
cap.release()
print(count)
ARaises an error
B4
C0
D5
Attempts:
2 left
💡 Hint

The loop increments count only when a frame is successfully read.