-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvideo_feed.py
More file actions
34 lines (28 loc) · 887 Bytes
/
video_feed.py
File metadata and controls
34 lines (28 loc) · 887 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import cv2
from imutils.video import FPS
import imutils
class VideoFeed:
def __init__(self, url, width=450, bw=True) -> None:
super().__init__()
self.url = url
self.feed = cv2.VideoCapture(url)
self.fps = FPS().start()
self.width = width
self.bw = bw
print("Is local video: " + str(self.local_video()))
def next_frame(self):
(grabbed, frame) = self.feed.read()
if not grabbed:
return None
frame = imutils.resize(frame, width=self.width)
if self.bw:
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
self.fps.update()
return frame
def close(self):
self.fps.stop()
self.feed.release()
cv2.destroyAllWindows()
print("fps: " + str(self.fps.fps()))
def local_video(self):
return "rtsp://" not in self.url