Skip to content

Instantly share code, notes, and snippets.

View masouduut94's full-sized avatar
👨‍👩‍👦‍👦
Family comes before Work.

Masoud Masoumi Moghadam masouduut94

👨‍👩‍👦‍👦
Family comes before Work.
View GitHub Profile
@masouduut94
masouduut94 / rtsp_threaded_tracker.py
Last active May 25, 2020 19:54
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)
@masouduut94
masouduut94 / rtsp_threaded_tracker.py
Last active May 25, 2020 20:17
pedestrian detection service on stream video provided by rtsp link
import warnings
from os import getenv
import sys
from os.path import dirname, abspath
sys.path.append(dirname(dirname(abspath(__file__))))
import torch
from deep_sort import build_tracker
from detector import build_detector
<html lang="en">
<head>
<title>Camera #1 </title>
</head>
<body>
<h1>Floor 2 </h1>
<img src="{{ url_for('video_feed') }}">
</body>
</html>
@masouduut94
masouduut94 / server_cfg.py
Last active May 26, 2020 16:12
Configuring deep learning models parameters in dictionary variables.
"""
Configuring deep learning models parameters in dictionary variables.
"""
import sys
from os.path import dirname, abspath, isfile
sys.path.append(dirname(dirname(abspath(__file__))))
from dotenv import load_dotenv
from utils.asserts import assert_in_env
@masouduut94
masouduut94 / rtsp_webserver.py
Last active May 26, 2020 16:37
This code handles the pedestrian detection service on specified camera. Also provides stream images for clients.
"""
This code handles the pedestrian detection service on specified camera.
Also provides stream images for clients.
"""
from os.path import join
from os import getenv, environ
from dotenv import load_dotenv
import argparse
@masouduut94
masouduut94 / basic_classes.py
Last active July 10, 2020 07:48
Initializing basic classes
class Label:
"""
For each bounding box there are various categories with confidences. Label class keeps track of that information.
"""
def __init__(self, category: str, confidence: float):
self.category = category
self.confidence = confidence
class JsonParser:
def __init__(self, top_k_labels: int = 1):
self.frames = {}
self.video_details = dict(frame_width=None,
frame_height=None,
frame_rate=None,
video_name=None)
self.top_k_labels = top_k_labels
import unittest
import sys
from unittest.case import TestCase
sys.path.append('../..')
from json_parser.json_parser import *
class TestFrame(TestCase):
def test_add_frame(self):
frames_ids = [1, 2, 3, 4, 5]
self.json_parser.set_top_k(0)
for frame_id in frames_ids:
self.json_parser.add_frame(frame_id)
output = self.json_parser.output()
output_ids = [frame['frame_id'] for frame in output['frames']]
for frame_id in frames_ids:
self.assertIn(frame_id, output_ids)
def set_top_k(self, value):
self.top_k_labels = value
def frame_exists(self, frame_id: int):
return frame_id in self.frames.keys()
def add_frame(self, frame_id: int):
# Use this function to add frames with index.
if not self.frame_exists(frame_id):
self.frames[frame_id] = Frame(frame_id)