-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvideoFeed.py
50 lines (39 loc) · 1.37 KB
/
videoFeed.py
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""
Simply display the contents of the webcam with optional mirroring using OpenCV
via the new Pythonic cv2 interface. Press <esc> to quit.
"""
import cv2
from utils.utils import setup_logging
logger = setup_logging()
class Video:
def __init__(self, video_path, source=None, resize=False, width=224, height=224):
self.source = source
self.resize = resize
self.video_path = video_path
self.width = width
self.height = height
def getImage(self):
if not self.source:
self.source = cv2.VideoCapture(self.video_path)
while True:
ret_val, img = self.source.read()
if self.resize:
# resize the image
img = cv2.resize(img, (self.width, self.height),
interpolation=cv2.INTER_AREA)
if not ret_val:
logger.info("End of Video frame")
yield None
yield img
if __name__ == '__main__':
video_path = "data/news.mp4"
video = Video(video_path=video_path)
images = video.getImage()
for img in images:
if img is None: # last frame
break
cv2.imshow('yield', img)
cv2.namedWindow('yield',cv2.WINDOW_NORMAL)
if cv2.waitKey(1) == 27:
break # esc to quit
cv2.destroyAllWindows()