0% found this document useful (0 votes)
27 views20 pages

Lec 7

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)
27 views20 pages

Lec 7

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/ 20

import cv2

cap = cv2.VideoCapture(0)
print("Check===", cap.isOpened())
fourcc = cv2.VideoWriter_fourcc(*"XVID")
output = cv2.VideoWriter("Output.avi",fourcc,20.0,(640,480),0)
while(cap.isOpened()):
ret, frame = cap.read()
if ret == True:
cv2.imshow('Colorframes', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break

cap.realease()
output.relaese()
cv2.destroyAllWindows()
Lec 7
IP Webcam
• Download & Install it from Play Store in your
mobile
• Install, click on the Start Server
• Connect the mobile with same WIFI or
Hotspot
• Access the camera in the browser and write
the IP address in browser address bar.
import cv2

camera = "http://192.168.98.137:8080/video"# Ip of the Camera


cap = cv2.VideoCapture(0) #Here Parameter 0 is a path of any video
cap.open(camera)
print("check===",cap.isOpened())
fourcc = cv2.VideoWriter_fourcc(*"XVID") #It contain four parameters: Name, Codec,
fps, Resolution
output = cv2.VideoWriter("output.avi",fourcc,20.0,(640,480),0)
while(cap.isOpened()):
ret, frame = cap.read() # Read the frame
if ret == True:
cv2.imshow('ColorFrame', frame)
if cv2.waitKey() & 0xFF == ord('q'): #Press to Exit
break

#Release Everything if job is finished


cap.release()
output.release()
cv2.destroyAllWindows()
import cv2

Resize
camera = "http://192.168.98.137:8080/video"# ca
cap = cv2.VideoCapture(0,cv2.CAP_DSHOW) #Here Parameter 0 is a path of any video
cap.open(camera)
print("check===",cap.isOpened())
fourcc = cv2.VideoWriter_fourcc(*"XVID") #It contain four parameters: Name, Codec, fps,
Resolution
output = cv2.VideoWriter("output.avi",fourcc,20.0,(640,480),0)
while(cap.isOpened()):
ret, frame = cap.read() # Read the frame
if ret == True:
cv2.resize(frame,(350,700))
cv2.imshow('ColorFrame', frame)
if cv2.waitKey() & 0xFF == ord('q'): #Press to Exit
break

#Release Everything if job is finished


cap.release()
output.release()
cv2.destroyAllWindows()
import cv2

camera = "http://192.168.98.137:8080/video"# ca
cap = cv2.VideoCapture(0,cv2.CAP_DSHOW) #Here Parameter 0 is a path of any video
cap.open(camera)
print("check===",cap.isOpened())
fourcc = cv2.VideoWriter_fourcc(*"XVID") #It contain four parameters: Name, Codec, fps,
Resolution
output = cv2.VideoWriter("output.avi",fourcc,20.0,(640,480),0)
while(cap.isOpened()):
ret, frame = cap.read() # Read the frame
if ret == True:
cv2.resize(frame,(175,175))
cv2.imshow('ColorFrame', frame)
if cv2.waitKey() & 0xFF == ord('q'): #Press to Exit
break

#Release Everything if job is finished


cap.release()
output.release()
cv2.destroyAllWindows()
YouTube Video Without Downloading
import pafy
Pip install pafy in anaconda prompt
Installed
# Capture Video From Youtube
import cv2
import pafy
url = "https://www.youtube.com/watch?v=wGxjfLilpCY"
data = pafy.new(url)
data = data.getbest(preftype="mp4")
cap = cv2.VideoCapture(0)# here parameter 0 is a path of any video
cap.open(data.url)
print("check===", cap.isOpened())

while(cap.isOpened()):
ret, frame = cap.read() #here read the frame
if ret == True:
frame = cv2.resize(frame,(700,700))
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.imshow('Colorframe', frame)
cv2.imshow('gray', gray)
if cv2.waitKey(1) & 0xFF ==ord('q'): #press to exit
break

cap.release()
cv2.destroyAllWindows()
Error
import cv2
from pytube import YouTube
# YouTube video URL GPT Code
video_url = 'https://www.youtube.com/watch?v=qYMk6JGm1iw'
# Downloading the video
yt = YouTube(video_url)
stream = yt.streams.filter(progressive=True, file_extension='mp4').first()
stream.download(filename='video')
# Playing the downloaded video using OpenCV
cap = cv2.VideoCapture('video.mp4')
while True:
ret, frame = cap.read()
if not ret:
break
# Display original video
cv2.imshow('Original Video', frame)
# Convert frame to grayscale
gray_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# Display grayscale video
cv2.imshow('Grayscale Video', gray_frame)
if cv2.waitKey(25) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
Assignment

You might also like