Python Module 2
Python Module 2
Module – 2
import cv2
cap = cv2.VideoCapture('video.mp4')
while cap.isOpened():
if not ret:
break
cv2.imshow('Video', frame)
break
cap.release()
1. AVI (.avi): Audio Video Interleave format, commonly used with MJPEG or XVID
codecs.
2. MP4 (.mp4): MPEG-4 format using H.264/H.265 codecs, widely used for compressed
video.
3. MOV (.mov): Apple QuickTime format, supports high-quality video, similar to MP4.
4. MKV (.mkv): Matroska format, supports multiple audio/video streams, open and
flexible.
5. FLV (.flv): Flash Video format, used in online streaming, requires FFMPEG support.
6. WMV (.wmv): Windows Media Video format, developed by Microsoft for Windows
systems.
7. Example: out.write(frame)
6. Name the parameters used in the cv2.putText() function to overlay date and time on a
video frame.
cap = cv2.VideoCapture(0)
fourcc = cv2.VideoWriter_fourcc(*'XVID')
while cap.isOpened():
if not ret:
break
out.write(frame)
cv2.imshow('Recording', frame)
break
cap.release()
out.release()
cv2.destroyAllWindows()
8. State the purpose of the cv2.line(), cv2.rectangle(), and cv2.circle() functions in video
processing.
9. Explain the process of adding date and time stamps to a video frame using OpenCV.
import cv2
cap = cv2.VideoCapture(0)
while True:
break
cap.release()
cv2.destroyAllWindows()
10. Describe how to detect faces in a video stream using Haar cascades in OpenCV.
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
cap = cv2.VideoCapture(0)
while True:
if cv2.waitKey(1) == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
11. Discuss the differences between read operations for video files and webcam feeds in
OpenCV.
4. Video files may require codec support; webcams use system drivers.
3. Brightness: cv2.CAP_PROP_BRIGHTNESS
4. Contrast: cv2.CAP_PROP_CONTRAST
13. Interpret the frame properties retrieved from a video file using cv2.CAP_PROP_* and
explain their significance.
14. Describe how resizing video frames affects the output video quality and file size.
16. Effect of Changing Video Frame Size on Quality and File Size
cv2.imshow('Frame', frame)
break
18. Controlling Video Playback Speed Using cv2.waitKey()
while True:
frame_id += 1
counter = 0
while True:
counter += 1