Skip to content

Commit 3b788a6

Browse files
committed
Cập nhật tối ưu giao diện và thêm chức năng phát hiện hành vi
1 parent 556ef0f commit 3b788a6

21 files changed

Lines changed: 3110 additions & 962 deletions

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,5 @@ snapshots/
5454
screenshots/
5555
captures/
5656
exports/
57-
outputs/
57+
outputs/
58+
comprehensive_evaluation.py

bot/service.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def _create_session_with_retry():
106106
session.mount("https://", adapter)
107107
return session
108108

109-
def send_photo(token: str, chat_id: str, photo_path: str, caption: str = "", reply_markup: Optional[dict] = None) -> bool:
109+
def send_photo(token: str, chat_id: str, photo_path: str, caption: str = "", reply_markup: Optional[dict] = None, disable_notification: bool = False) -> bool:
110110
for attempt in range(3):
111111
try:
112112
url = f"https://api.telegram.org/bot{token}/sendPhoto"
@@ -118,7 +118,7 @@ def send_photo(token: str, chat_id: str, photo_path: str, caption: str = "", rep
118118
else:
119119
files = {'photo': open(photo_path, 'rb')}
120120

121-
data = {'chat_id': chat_id, 'caption': caption}
121+
data = {'chat_id': chat_id, 'caption': caption, 'disable_notification': disable_notification}
122122
if reply_markup: data['reply_markup'] = json.dumps(reply_markup)
123123

124124
response = session.post(url, files=files, data=data, timeout=30)
@@ -394,11 +394,21 @@ def _setup_handlers(self):
394394
self.app.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, self.handlers.message_listener))
395395
self.app.add_handler(CallbackQueryHandler(self.handlers.button_callback_handler))
396396

397-
def schedule_alert(self, chat_id: str, image_path: str, caption: str, alert_id: str, is_fire: bool = False):
397+
def schedule_alert(self, chat_id: str, image_path: str, caption: str, alert_id: str, is_fire: bool = False, disable_notification: bool = False):
398398
if not TELEGRAM_AVAILABLE: return
399399
kb = create_fire_alert_keyboard(alert_id) if is_fire else create_person_alert_keyboard(alert_id)
400400
markup = kb.to_dict() if kb else None
401-
threading.Thread(target=lambda: send_photo(settings.telegram.token, chat_id, image_path, caption, reply_markup=markup), daemon=True).start()
401+
threading.Thread(
402+
target=lambda: send_photo(
403+
settings.telegram.token,
404+
chat_id,
405+
image_path,
406+
caption,
407+
reply_markup=markup,
408+
disable_notification=disable_notification
409+
),
410+
daemon=True
411+
).start()
402412

403413
def schedule_person_alert(self, chat_id: str, image_path: str, caption: str, alert_id: str):
404414
"""Schedules a person alert. Alias for schedule_alert with is_fire=False."""

config/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# config/__init__.py
2-
from .settings import settings, Settings, AlertType, ActionCode
2+
from .settings import settings, Settings, AlertType, AlertPriority, ActionCode
33

4-
__all__ = ['settings', 'Settings', 'AlertType', 'ActionCode']
4+
__all__ = ['settings', 'Settings', 'AlertType', 'AlertPriority', 'ActionCode']

config/config.yaml

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ camera:
6868
mp4:
6969
person_detection_enabled: false
7070
detection:
71-
face_recognition_threshold: 0.4
71+
face_recognition_threshold: 0.45
7272
fire_confidence_threshold: 0.85
7373
global_enabled: true
7474
iou_threshold: 0.6
@@ -91,9 +91,9 @@ fire_logic:
9191
yellow_alert_frames: 8
9292
models:
9393
face:
94-
detector_name: buffalo_l
95-
recognizer_name: buffalo_l
96-
face_model_name: buffalo_l
94+
detector_name: Small
95+
recognizer_name: Small
96+
face_model_name: Small
9797
insightface_ctx_id: 0
9898
insightface_det_size:
9999
- 640
@@ -130,6 +130,19 @@ tracker:
130130
stranger_confirm_frames: 20
131131
timeout_seconds: 2.0
132132
video_preview_limit_mb: 48.0
133+
behavior:
134+
enabled: true
135+
model_path: Data/Model/anomaly_model.pth
136+
device: cuda
137+
threshold: 0.5
138+
alert_cooldown: 30
139+
window_size: 64
140+
stride: 16
141+
num_segments: 32
142+
model_complexity: 1
143+
min_detection_confidence: 0.5
144+
min_tracking_confidence: 0.5
145+
process_every_n_frames: 1
133146
optimization:
134147
frame_resize_enabled: true
135148
frame_resize_width: 1280

config/settings.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,14 @@ class AlertType(Enum):
115115
STRANGER = "nguoi_la"
116116
FIRE_WARNING = "lua_chay_nghi_ngo"
117117
FIRE_CRITICAL = "lua_chay_khan_cap"
118+
ANOMALOUS_BEHAVIOR = "hanh_vi_bat_thuong"
119+
120+
class AlertPriority(Enum):
121+
"""Alert priority levels for different response urgency"""
122+
CRITICAL = 1 # Fire alerts - immediate action required
123+
HIGH = 2 # Stranger with anomalous behavior - security threat
124+
MEDIUM = 3 # Stranger only - security monitoring
125+
LOW = 4 # Known person - informational
118126

119127
class ActionCode(Enum):
120128
TOGGLE_ON = "TOGGLE_ON"

0 commit comments

Comments
 (0)