Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
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.
✗ Incorrect
The 'XVID' codec is commonly used for AVI video writing in OpenCV.
2fill in blank
mediumComplete 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'
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.
✗ Incorrect
The VideoWriter object 'out' is used to write frames to the video file.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Calling release on the capture object instead of the writer.
Forgetting to release the writer causing file corruption.
✗ Incorrect
The release() method must be called on the VideoWriter object 'out' to properly close the file.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong codec string causing unsupported format.
Setting FPS to a wrong value causing playback issues.
✗ Incorrect
MJPG is a common codec and 30.0 sets the frames per second to 30.
5fill in blank
hardFill 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'
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.
✗ Incorrect
Check if ret is True, convert frame to grayscale using cv2.COLOR_BGR2GRAY, then write using 'out'.