Last active
May 25, 2020 19:54
-
-
Save masouduut94/5516f94be0c18994924f7087516bdd31 to your computer and use it in GitHub Desktop.
Threading-based rtsp reader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
from concurrent.futures import ThreadPoolExecutor | |
from redis import Redis | |
redis_cache = Redis('127.0.0.1') | |
class RealTimeTracking(object): | |
def __init__(self, src): | |
self.vdo = cv2.VideoCapture(self.args.input) | |
self.status, self.frame = None, None | |
self.output_frame = None | |
self.thread = ThreadPoolExecutor(max_workers=1) | |
self.thread.submit(self.update) | |
def update(self): | |
while True: | |
if self.vdo.isOpened(): | |
(self.status, self.frame) = self.vdo.read() | |
def run(self): | |
print('streaming started ...') | |
while True: | |
try: | |
redis_cache.set('frame', frame_to_bytes) | |
except AttributeError: | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment