0
0
Computer Visionml~10 mins

Real-time processing patterns in Computer Vision - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
Acapture
Bread
Cget
Dgrab
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.
2fill in blank
medium

Complete 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'
AconvertColor
BtransformColor
CchangeColor
DcvtColor
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'convertColor' which is not a valid OpenCV function.
Using 'changeColor' or 'transformColor' which do not exist.
3fill in blank
hard

Fix 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'
A7
B3
C5
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 or even numbers which cause errors.
Using mismatched kernel sizes.
4fill in blank
hard

Fill 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'
AcvtColor
B<
C>
DconvertColor
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'convertColor' which is invalid.
Using '>' which selects frames after index 5.
5fill in blank
hard

Fill 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'
AcvtColor
B3
DconvertColor
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'convertColor' which is invalid.
Using even kernel sizes or zeros.