Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to capture video frames in real-time using OpenCV.
Computer Vision
import cv2 cap = cv2.VideoCapture(0) while True: ret, frame = cap.[1]() if not ret: break cv2.imshow('Frame', frame) if cv2.waitKey(1) & 0xFF == ord('q'): break cap.release() cv2.destroyAllWindows()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'grab()' which only grabs the frame but does not decode it.
Using 'get()' which retrieves properties, not frames.
✗ Incorrect
The method 'read()' captures a frame from the video stream and returns a success flag and the frame itself.
2fill in blank
mediumComplete the code to convert a captured frame to grayscale for faster processing.
Computer Vision
import cv2 frame = cv2.imread('image.jpg') gray = cv2.[1](frame, cv2.COLOR_BGR2GRAY)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'convertColor' which is not a valid OpenCV function.
Using 'changeColor' or 'transformColor' which do not exist.
✗ Incorrect
The correct OpenCV function to convert color spaces is 'cvtColor'.
3fill in blank
hardFix the error in the code to apply a Gaussian blur to the frame.
Computer Vision
import cv2 frame = cv2.imread('image.jpg') blurred = cv2.GaussianBlur(frame, ([1], 5), 0)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 or even numbers which cause errors.
Using mismatched kernel sizes.
✗ Incorrect
The kernel size must be a tuple of odd numbers. (5,5) is valid; here the first value is missing and should be 5.
4fill in blank
hardFill both blanks to create a dictionary comprehension that maps frame indices to their grayscale versions.
Computer Vision
frames_gray = {i: cv2.[1](frame, cv2.COLOR_BGR2GRAY) 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
Using 'convertColor' which is invalid.
Using '>' which selects frames after index 5.
✗ Incorrect
Use 'cvtColor' to convert frames to grayscale and '<' to select frames with index less than 5.
5fill in blank
hardFill all three blanks to create a dictionary of frame indices and their blurred grayscale frames for frames with index greater than 2.
Computer Vision
blurred_frames = {i: cv2.GaussianBlur(cv2.[1](frame, cv2.COLOR_BGR2GRAY), ([2], [3]), 0) for i, frame in enumerate(frames) if i > 2} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'convertColor' which is invalid.
Using even kernel sizes or zeros.
✗ Incorrect
Use 'cvtColor' to convert to grayscale and (3,3) as the kernel size for Gaussian blur.