-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathstream.py
More file actions
executable file
·43 lines (33 loc) · 1010 Bytes
/
stream.py
File metadata and controls
executable file
·43 lines (33 loc) · 1010 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
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Jun 28 00:48:02 2022
@author: prabhakar
"""
import cv2
import threading
class Video:
def __init__(self, video_src, width, height, fps):
self.stream = cv2.VideoCapture(video_src)
self.stream.set(3, width)
self.stream.set(4, height)
self.stream.set(5, fps)
(self.grabbed, self.frame) = self.stream.read()
self.stopped = False
self.count = 0
def start(self):
threading.Thread(target=self.update, args=()).start()
return self
def update(self):
while True:
if self.stopped:
self.stream.release()
return
(self.grabbed, self.frame) = self.stream.read()
self.count+=1
def read_frame(self):
return self.grabbed, self.frame, self.count
def get_shape(self):
return self.frame.shape
def stop(self):
self.stopped = True