Lab 6
Lab 6
Aim: To implement Basic Video Processing operations using OpenCV in Python. Specifically,
to implement basic video operations like capturing a video from the PC's camera ,
converting the video into frames and storing them, displaying the frames at various
fps(frames per second, e.g. 25 fps, 50 fps etc).
Theory:
Video Processing: Video processing involves manipulating video data, such as capturing
video from a camera, converting it into frames, and performing operations like object
detection or frame extraction.
OpenCV: OpenCV is a popular open-source library for computer vision tasks, including video
capture, frame manipulation, and image processing.
Frames per Second (FPS): FPS measures how many frames are processed or displayed per
second. Adjusting FPS controls the speed of video playback, with higher FPS resulting in
smoother video.
Algorithm:
● Loop to capture frames, save each as an image, and display them at different FPS.
● Release the video capture object and close all OpenCV windows.
Program Code:
import cv2
import os
import time
if not os.path.exists('frames'):
os.makedirs('frames')
cap = cv2.VideoCapture(0)
frame_count = 0
while cap.isOpened():
ret, frame = cap.read()
if not ret:
print("Failed to capture video")
break
frame_filename = f'frames/frame_{frame_count}.jpg'
cv2.imwrite(frame_filename, frame)
cv2.imshow('Video Frame', frame)
key = cv2.waitKey(1)
if key == ord('q'):
break
for fps in fps_list:
time.sleep(1/fps)
frame_count += 1
cap.release()
cv2.destroyAllWindows()
Conclusion:
This implementation demonstrates the basics of video processing using OpenCV, including
capturing video, converting it to frames, and displaying frames at different FPS rates. The
ability to manipulate FPS and store frames provides a foundation for more complex video
processing tasks, such as video analysis and editing.
Output: