Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to open a video file using OpenCV.
Computer Vision
import cv2 cap = cv2.VideoCapture([1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the filename
Passing a variable name without quotes
✗ Incorrect
The VideoCapture function expects a string path to the video file, so the filename must be in quotes.
2fill in blank
mediumComplete the code to read a frame from the video capture object.
Computer Vision
ret, frame = cap.[1]() Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using cap.get() which retrieves properties, not frames
Using incorrect method names like capture() or fetch()
✗ Incorrect
The read() method reads the next frame from the video capture object.
3fill in blank
hardFix the error in the loop condition to properly check if the frame was read.
Computer Vision
while cap.isOpened(): ret, frame = cap.read() if not [1]: break
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Checking 'if not frame:' which can cause errors
Using 'if not cap:' which is incorrect
✗ Incorrect
The variable 'ret' is a boolean indicating if the frame was read successfully.
4fill in blank
hardFill both blanks to convert the frame to grayscale and display it.
Computer Vision
gray = cv2.[1](frame, cv2.[2]) cv2.imshow('Gray Frame', gray)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using resize instead of cvtColor
Using COLOR_RGB2GRAY when frames are in BGR format
✗ Incorrect
Use cvtColor to convert color spaces and COLOR_BGR2GRAY to convert BGR to grayscale.
5fill in blank
hardFill all three blanks to release the video and close all OpenCV windows.
Computer Vision
cap.[1]() cv2.[2]() cv2.[3](0)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to release the video capture
Not closing windows properly
Using imshow instead of waitKey
✗ Incorrect
release() frees the video resource, destroyAllWindows() closes windows, and waitKey() waits for a key press.