Lec 7
Lec 7
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
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
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
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