Update app.py
Browse files
app.py
CHANGED
|
@@ -7,9 +7,9 @@ from PIL import Image as PILImage
|
|
| 7 |
import io
|
| 8 |
import os
|
| 9 |
import base64
|
| 10 |
-
|
| 11 |
import torch
|
| 12 |
|
|
|
|
| 13 |
class SafetyMonitor:
|
| 14 |
def __init__(self):
|
| 15 |
"""Initialize Safety Monitor with configuration."""
|
|
@@ -44,6 +44,14 @@ class SafetyMonitor:
|
|
| 44 |
return cv2.resize(image, (new_width, new_height), interpolation=cv2.INTER_AREA)
|
| 45 |
return image
|
| 46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
def detect_objects(self, frame):
|
| 48 |
"""Detect objects using YOLOv5."""
|
| 49 |
results = self.yolo_model(frame)
|
|
|
|
| 7 |
import io
|
| 8 |
import os
|
| 9 |
import base64
|
|
|
|
| 10 |
import torch
|
| 11 |
|
| 12 |
+
|
| 13 |
class SafetyMonitor:
|
| 14 |
def __init__(self):
|
| 15 |
"""Initialize Safety Monitor with configuration."""
|
|
|
|
| 44 |
return cv2.resize(image, (new_width, new_height), interpolation=cv2.INTER_AREA)
|
| 45 |
return image
|
| 46 |
|
| 47 |
+
def encode_image(self, frame):
|
| 48 |
+
"""Convert image to base64 encoding."""
|
| 49 |
+
frame_pil = PILImage.fromarray(frame)
|
| 50 |
+
buffered = io.BytesIO()
|
| 51 |
+
frame_pil.save(buffered, format="JPEG", quality=95)
|
| 52 |
+
img_base64 = base64.b64encode(buffered.getvalue()).decode('utf-8')
|
| 53 |
+
return f"data:image/jpeg;base64,{img_base64}"
|
| 54 |
+
|
| 55 |
def detect_objects(self, frame):
|
| 56 |
"""Detect objects using YOLOv5."""
|
| 57 |
results = self.yolo_model(frame)
|