0
0
Computer Visionml~10 mins

Video writing 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 writer with the correct fourcc codec.

Computer Vision
import cv2
fourcc = cv2.VideoWriter_fourcc(*'[1]')
out = cv2.VideoWriter('output.avi', fourcc, 20.0, (640,480))
Drag options to blanks, or click blank then click option'
AH264
BMP4V
CMJPG
DXVID
Attempts:
3 left
💡 Hint
Common Mistakes
Using an unsupported codec string causes the video writer to fail.
Forgetting to unpack the string with * in VideoWriter_fourcc.
2fill in blank
medium

Complete the code to write a frame to the video file.

Computer Vision
ret, frame = cap.read()
if ret:
    [1].write(frame)
Drag options to blanks, or click blank then click option'
Acap
Bout
Cframe
Dcv2
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to write frames using the capture object 'cap'.
Calling write on the frame itself instead of the writer.
3fill in blank
hard

Fix the error in the code to release the video writer properly.

Computer Vision
out = cv2.VideoWriter('output.avi', fourcc, 20.0, (640,480))
# ... writing frames ...
[1].release()
Drag options to blanks, or click blank then click option'
Acv2
Bframe
Cout
Dcap
Attempts:
3 left
💡 Hint
Common Mistakes
Calling release on the capture object instead of the writer.
Forgetting to release the writer causing file corruption.
4fill in blank
hard

Fill both blanks to create a VideoWriter with MJPG codec and 30 FPS.

Computer Vision
fourcc = cv2.VideoWriter_fourcc(*'[1]')
out = cv2.VideoWriter('output.avi', fourcc, [2], (640,480))
Drag options to blanks, or click blank then click option'
AMJPG
BXVID
C30.0
D20.0
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong codec string causing unsupported format.
Setting FPS to a wrong value causing playback issues.
5fill in blank
hard

Fill all three blanks to write frames only if the frame is read successfully and convert it to grayscale before writing.

Computer Vision
ret, frame = cap.read()
if [1]:
    gray = cv2.cvtColor(frame, [2])
    [3].write(gray)
Drag options to blanks, or click blank then click option'
Aret
Bcv2.COLOR_BGR2GRAY
Cout
Dframe
Attempts:
3 left
💡 Hint
Common Mistakes
Writing frames without checking if read was successful.
Using wrong color conversion code causing errors.
Writing to the wrong object instead of the VideoWriter.