0
0
Computer Visionml~10 mins

Reading video with OpenCV 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"
Bvideo.mp4
C123
DTrue
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the filename
Passing a variable name without quotes
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'
Afetch
Bcapture
Cget
Dread
Attempts:
3 left
💡 Hint
Common Mistakes
Using cap.get() which retrieves properties, not frames
Using incorrect method names like capture() or fetch()
3fill in blank
hard

Fix 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'
Aret
Bframe
Ccap
DTrue
Attempts:
3 left
💡 Hint
Common Mistakes
Checking 'if not frame:' which can cause errors
Using 'if not cap:' which is incorrect
4fill in blank
hard

Fill 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'
AcvtColor
BCOLOR_BGR2GRAY
CCOLOR_RGB2GRAY
Dresize
Attempts:
3 left
💡 Hint
Common Mistakes
Using resize instead of cvtColor
Using COLOR_RGB2GRAY when frames are in BGR format
5fill in blank
hard

Fill 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'
Arelease
BdestroyAllWindows
CwaitKey
Dimshow
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to release the video capture
Not closing windows properly
Using imshow instead of waitKey