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

Lec 5

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 views25 pages

Lec 5

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

Video Operation using OpenCV

Lecture 5
cap = [Link]("F:\First Semester 2024\Computer Vision\lec5.mp4")

• cap is an object to read the video


Code
import cv2
cap = [Link]("F:\First Semester 2024\Computer Vision\lec5.mp4")
print("cap",cap)

while True:
ret,frame = [Link]()

[Link]("frame", frame)
[Link]()

[Link]()
[Link]()

ret ;is boolean value either there is frame or not


Resize the Video Size
Resize Code
import cv2
cap = [Link]("F:\First Semester 2024\Computer Vision\lec5.mp4")
print("cap",cap)

while True:
ret,frame = [Link]()
frame = [Link](frame,(700,450))
[Link]("frame", frame)
[Link]()

[Link]()
[Link]()
cap = [Link]("F:\First Semester 2024\Computer Vision\lec5.mp4")
Code
import cv2
cap = [Link]("F:\First Semester 2024\Computer Vision\lec5.mp4")
print("cap",cap)
while True:
ret,frame = [Link]()
frame = [Link](frame,(700,450))
[Link]("frame", frame)
k = [Link]()
if k == ord("q"):
break
[Link](25)
[Link]()
ret,frame = [Link]()
• Ret is boolean value
• Frame is any image
End the Video by press q
import cv2
• k = [Link]() cap = [Link]("F:\First Semester
2024\Computer Vision\lec5.mp4")
• if k == ord("q"): print("cap",cap)

• break while True:


ret,frame = [Link]()
frame = [Link](frame,(700,450))
[Link]("frame", frame)
k = [Link]()
if k == ord("q"):
break
[Link]()
[Link]()
64 bit error Mask
import cv2
cap = [Link]("F:\First Semester 2024\Computer Vision\lec5.mp4")
print("cap",cap)

while True:
ret,frame = [Link]()
frame = [Link](frame,(700,450))
[Link]("frame", frame)
k = [Link]()
if k == ord("q") & 0xFF:
break

[Link]()
[Link]()
To convert the frame into Grayscale
To convert the frame into Grayscale
import cv2
cap = [Link]("F:\First Semester 2024\Computer Vision\
lec5.mp4")
print("cap",cap)

while True:
ret,frame = [Link]()
frame = [Link](frame,(700,450))
gray = [Link](frame, cv2.COLOR_BGR2GRAY)
[Link]("frame", frame)
[Link]("gray", gray)
k = [Link]()
if k == ord("q") & 0xFF:
break

[Link]()
[Link]()
[Link](100)
• Play Back Speed (SLOW MO)
Read Video From WebCam & Save it to
Memory
• cap = [Link](0)
• For webcam camera 0 for external camera 1
Read Video From WebCam
import cv2
#Now capture video from webcam and save it to memeory
cap = [Link](0,cv2.CAP_DSHOW)
print(cap)
while [Link]():
ret,frame = [Link]()
if ret == True:
frame =[Link](frame,(700,450))
gray = [Link](frame,cv2.COLOR_BGR2GRAY)
[Link]('frame',frame)
[Link]("gray", gray)
if [Link](1) & 0xFF == ord('q'): #Press to exit
break

[Link]()
[Link]()
Save it to Memory
Save it to Memory (Continued)
import cv2
#Now capture video from webcam and save it to memeory
cap = [Link](0,cv2.CAP_DSHOW)

#DIVX, XVID, MJPG, X264, WMV1, WMV2


fourcc = cv2.VideoWriter_fourcc(*"XVID") # "XVID"
# It contain four parameter, name, codec, fps, resolution
output = [Link]("F:\First Semester 2024\Computer Vision\[Link]", fourcc,20.0,
(640,480))
print(cap)
while [Link]():
ret,frame = [Link]()
if ret == True:

gray = [Link](frame,cv2.COLOR_BGR2GRAY)
[Link]('frame',frame)
[Link]("gray", gray)
[Link](frame)
if [Link](1) & 0xFF == ord('q'): #Press to exit
break

[Link]()
[Link]()
[Link]()
import cv2
To save the video in grayscale
#Now capture video from webcam and save it to memeory
cap = [Link](0,cv2.CAP_DSHOW)

#DIVX, XVID, MJPG, X264, WMV1, WMV2


fourcc = cv2.VideoWriter_fourcc(*"XVID") # "XVID"
# It contain four parameter, name, codec, fps, resolution
output = [Link]("F:\First Semester 2024\Computer Vision\[Link]", fourcc,20.0,
(640,480),0)
print(cap)
while [Link]():
ret,frame = [Link]()
if ret == True:

gray = [Link](frame,cv2.COLOR_BGR2GRAY)
[Link]('frame',frame)
[Link]("gray", gray)
[Link](gray)
if [Link](1) & 0xFF == ord('q'): #Press to exit
break

[Link]()
[Link]()
[Link]()
To flip the frame
import cv2
#Now capture video from webcam and save it to memeory
cap = [Link](0,cv2.CAP_DSHOW)

#DIVX, XVID, MJPG, X264, WMV1, WMV2


fourcc = cv2.VideoWriter_fourcc(*"XVID") # "XVID"
# It contain four parameter, name, codec, fps, resolution
output = [Link]("F:\First Semester 2024\Computer Vision\[Link]", fourcc,20.0,
(640,480),0)
print(cap)
while [Link]():
ret,frame = [Link]()
if ret == True:

gray = [Link](frame,cv2.COLOR_BGR2GRAY)
frame = [Link](frame,0)
[Link]('frame',frame)
[Link]("gray", gray)
[Link](gray)
if [Link](1) & 0xFF == ord('q'): #Press to exit
break

[Link]()
[Link]()
[Link]()
Gray Frame Flip

You might also like