0% found this document useful (0 votes)
4 views3 pages

Lab 6

Lab 6

Uploaded by

joanhazan05
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Lab 6

Lab 6

Uploaded by

joanhazan05
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

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:

● Import cv2, os, and time.

● Use cv2.VideoCapture(0) to capture video from the default camera.

● Check if the frames directory exists; or else, create one.

● Specify FPS rates, such as 25 FPS and 50 FPS.

● Loop to capture frames, save each as an image, and display them at different FPS.

● Allow the user to press 'q' to exit the loop.

● 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)

fps_list = [25, 50]

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:

Frames captured at [25, 50]

You might also like