Skip to content

Instantly share code, notes, and snippets.

@masouduut94
Last active May 25, 2020 19:54
Show Gist options
  • Save masouduut94/5516f94be0c18994924f7087516bdd31 to your computer and use it in GitHub Desktop.
Save masouduut94/5516f94be0c18994924f7087516bdd31 to your computer and use it in GitHub Desktop.
Threading-based rtsp reader
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