Replace streamlit with FastAPI

This commit is contained in:
Jakob Lechner 2025-08-02 03:25:54 +02:00
parent 82263557af
commit 91f4d70a77
7 changed files with 228 additions and 82 deletions

View file

@ -1,23 +1,25 @@
class Counter:
def __init__(self, line_orientation, metrics):
def __init__(self, stream_id, line_orientation, metrics):
self.in_count = 0
self.out_count = 0
self.track_memory = {}
self.line_orientation = line_orientation
self.metrics = metrics
self.stream_id = stream_id
def update(self, tracks, line_position):
for track in tracks:
track_id = track.id
x, y, w, h = track.bbox
if self.line_orientation == 'horizontal':
if self.line_orientation == "horizontal":
center = int(y + h / 2)
elif self.line_orientation == 'vertical':
elif self.line_orientation == "vertical":
center = int(x + w / 2)
else:
raise NotImplementedError(f'Line orientation {self.line_orientation} is invalid!')
raise NotImplementedError(
f"Line orientation {self.line_orientation} is invalid!"
)
if track_id not in self.track_memory:
self.track_memory[track_id] = center
@ -28,7 +30,7 @@ class Counter:
if prev < line_position <= center:
self.in_count += 1
self.metrics["people_in"].inc()
self.metrics["people_in"].labels(stream=self.stream_id).inc()
elif prev > line_position >= center:
self.out_count += 1
self.metrics["people_out"].inc()
self.metrics["people_out"].labels(stream=self.stream_id).inc()

View file

@ -1,10 +1,12 @@
import cv2
def draw_count_line_horizontal(frame, y):
color = (0, 255, 255)
thickness = 2
cv2.line(frame, (0, y), (frame.shape[1], y), color, thickness)
def draw_count_line_vertical(frame, x):
color = (0, 255, 255)
thickness = 2