Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to load a video file using OpenCV.
Prompt Engineering / GenAI
import cv2 video = cv2.VideoCapture([1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to put the filename in quotes.
Passing the filename without quotes causing a NameError.
✗ Incorrect
The cv2.VideoCapture function expects a string filename, so the filename must be in quotes.
2fill in blank
mediumComplete the code to read a frame from the video.
Prompt Engineering / GenAI
ret, frame = video.[1]() Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent methods like get_frame or capture.
Confusing method names with other libraries.
✗ Incorrect
The correct method to read a frame from a VideoCapture object is read().
3fill in blank
hardFix the error in the code to convert a frame to grayscale.
Prompt Engineering / GenAI
gray = cv2.cvtColor(frame, [1]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using COLOR_RGB2GRAY which is incorrect for OpenCV frames.
Using COLOR_GRAY2BGR which converts grayscale to color.
✗ Incorrect
Frames from OpenCV are in BGR format, so to convert to grayscale use COLOR_BGR2GRAY.
4fill in blank
hardFill both blanks to create a dictionary of frame indices and their grayscale frames for frames with index less than 5.
Prompt Engineering / GenAI
frames_dict = {i: [1] for i, frame in enumerate(frames) if i [2] 5} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Not converting frames to grayscale in the dictionary.
Using wrong comparison operator like <= instead of <.
✗ Incorrect
We convert each frame to grayscale and include frames with index less than 5.
5fill in blank
hardFill all three blanks to extract frames, convert to grayscale, and store only frames with brightness above 100.
Prompt Engineering / GenAI
filtered_frames = {i: [1] for i, frame in enumerate(video_frames) if cv2.mean([2])[0] [3] 100} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using COLOR_RGB2GRAY which is incorrect for OpenCV frames.
Comparing brightness with < instead of >.
Applying cv2.mean on grayscale frame instead of original.
✗ Incorrect
Convert frames to grayscale, check brightness with cv2.mean on original frame, and filter frames with brightness > 100.