0% found this document useful (0 votes)
11 views14 pages

Lecture 8

Uploaded by

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

Lecture 8

Uploaded by

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

Screen Recording using OpenCV

Lecture 8
Install pyautogui
Installed
Numpy Already Installed
#Screen Recorder
import cv2 as c
import pyautogui as p
import numpy as np
#Creat resolution
rs = p.size()
#file name in which we store recording
fn = input("please enter any file name and path")
#fix the frame rate
fps = 60.0
fourcc = c.VideoWriter_fourcc(*"XVID")
output = c.VideoWriter(fn, fourcc, fps, rs)
#Creating Recording Module
c.namedWindow("Live_Recording",c.WINDOW_NORMAL)
c.resizeWindow("Live_Recording", (600,400))
while True:
img = p.screenshot()
f = np.array(img)
f = c.cvtColor(f, c.COLOR_BGR2RGB)
output.write(f)
c.imshow("Live_Recording",f)
if c.waitKey(1) ==ord("q"):
break
output.release()
c.destroyAllWindows()
Project 2

BREAK VIDEO INTO MULTIPLE


IMAGES AND STORE IT IN A FOLDER
import cv2

vidcap = cv2.VideoCapture("F:\screen_again.mp4")
ret,image = vidcap.read()#READ THE VIDEO

count = 0

while True:
if ret == True:
cv2.imwrite("F:\\frames\\imgN%d.jpg" % count, image) # save frame as JPEG file
vidcap.set(cv2.CAP_PROP_POS_MSEC,(count**100)) #used to hold speed of frane generation
ret,image = vidcap.read()
cv2.imshow("res",image)
print ('Read a new frame:',count ,ret)
count += 1
if cv2.waitKey(1) & 0xFF == ord("q"):
break
cv2.destroyAllWindows()
else:
break

vidcap.release()
cv2.destroyAllWindows()
import cv2

vidcap = cv2.VideoCapture("F:\First Semester 2024\Computer Vision\lec5.mp4")


ret,image = vidcap.read()#READ THE VIDEO

count = 0

while True:
if ret == True:
cv2.imwrite("F:\\frames\\imgN%d.jpg" % count, image) # save frame as JPEG file
vidcap.set(cv2.CAP_PROP_POS_MSEC,(count**100)) #used to hold speed of frane generation
ret,image = vidcap.read()
cv2.imshow("res",image)
print ('Read a new frame:',count ,ret)
count += 1
if cv2.waitKey(1) & 0xFF == ord("q"):
break
cv2.destroyAllWindows()
else:
break

vidcap.release()
cv2.destroyAllWindows()

You might also like