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
def output(self):
output = {'video_details': self.video_details}
result = list(self.frames.values())
output['frames'] = [item.dic() for item in result]
return output
class BaseJsonParser(object):
"""
This is the base class that returns __dict__ of its own
it also returns the dicts of objects in the attributes that are list instances
"""
def dic(self):
# returns dicts of objects
out = {}
for k, v in self.__dict__.items():
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)
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)
import unittest
import sys
from unittest.case import TestCase
sys.path.append('../..')
from json_parser.json_parser import *
class TestFrame(TestCase):
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
@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
@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 / 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
<html lang="en">
<head>
<title>Camera #1 </title>
</head>
<body>
<h1>Floor 2 </h1>
<img src="{{ url_for('video_feed') }}">
</body>
</html>