0
0
Computer Visionml~10 mins

Frame extraction 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 open a video file using OpenCV.

Computer Vision
import cv2

cap = cv2.VideoCapture([1])
Drag options to blanks, or click blank then click option'
A'video.mp4'
B0
CTrue
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Passing 0 opens the webcam, not a video file.
Passing True or None causes errors.
2fill in blank
medium

Complete 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'
Aread
Bcapture
Cgrab
Dfetch
Attempts:
3 left
💡 Hint
Common Mistakes
Using grab() only grabs the frame but does not decode it.
capture() and fetch() are not OpenCV methods.
3fill in blank
hard

Fix the error in the loop that extracts frames until the video ends.

Computer Vision
while True:
    ret, frame = cap.read()
    if not [1]:
        break
    cv2.imshow('Frame', frame)
    if cv2.waitKey(25) & 0xFF == ord('q'):
        break
Drag options to blanks, or click blank then click option'
Aframe
Bret
Ccap
Dcv2
Attempts:
3 left
💡 Hint
Common Mistakes
Checking frame instead of ret can cause errors if frame is None.
Checking cap or cv2 is incorrect.
4fill in blank
hard

Fill both blanks to release the video and close all windows.

Computer Vision
cap.[1]()
cv2.[2]()
Drag options to blanks, or click blank then click option'
Arelease
BdestroyAllWindows
Cclose
Dstop
Attempts:
3 left
💡 Hint
Common Mistakes
Using close() or stop() are not valid OpenCV methods.
Not releasing the video can cause resource leaks.
5fill in blank
hard

Fill all three blanks to save the extracted frame as an image file.

Computer Vision
if ret:
    cv2.[1]('[2]', [3])
Drag options to blanks, or click blank then click option'
Aimwrite
Bframe
Coutput.jpg
Dimshow
Attempts:
3 left
💡 Hint
Common Mistakes
Using imshow instead of imwrite displays the image but does not save it.
Swapping filename and image arguments causes errors.