-
Notifications
You must be signed in to change notification settings - Fork 41
/
VideoFeed.py
32 lines (27 loc) · 937 Bytes
/
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
# Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
import cv2
import numpy as np
import thread
from threading import Lock
class VideoFeed:
'''Reads video frames and passes them on'''
def __init__(self, camera_port=0):
self.cap = cv2.VideoCapture(camera_port)
self.ret, self.img = self.cap.read()
self.thread_handle = None
self.stopped = True
self.lock = Lock()
def start(self):
'''starts new thread for video feed capture'''
self.stopped = False
self.thread_handle = thread.start_new_thread(self.frame_update, ())
def frame_update(self):
'''Continuously captures and updates frame'''
while not self.stopped:
self.ret, self.img = self.cap.read()
def read(self):
''' return image captured'''
return self.img
def stop(self):
'''stops video feed thread'''
self.stopped = True