From 0c33dd059fb56730e96e44bfd91f687f69d7e3e5 Mon Sep 17 00:00:00 2001 From: Masonmason Date: Wed, 16 Apr 2025 17:50:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=20video=20inference=20?= =?UTF-8?q?=E5=9B=9E=E5=82=B3=E7=82=BA=20none=20=E6=99=82=E6=9C=83?= =?UTF-8?q?=E5=87=BA=E7=8F=BE=E5=A4=A7=E9=87=8F=E7=9A=84=20popup=20?= =?UTF-8?q?=E5=B0=8E=E8=87=B4=20crash,=20=E6=9B=B4=E6=96=B0=20update=5Fdia?= =?UTF-8?q?ry.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/models/inference_worker.py | 9 +++++++-- src/views/mainWindows.py | 13 ++++++++++++- update_diary.md | 12 +++++++++++- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/models/inference_worker.py b/src/models/inference_worker.py index 51364a7..526f84f 100644 --- a/src/models/inference_worker.py +++ b/src/models/inference_worker.py @@ -54,7 +54,9 @@ class InferenceWorkerThread(QThread): try: mse = np.mean((frame.astype(np.float32) - self.last_frame.astype(np.float32)) ** 2) if mse < self.mse_threshold and self.cached_result is not None: - self.inference_result_signal.emit(self.cached_result) + # 只有在結果不為 None 時才發送信號 + if self.cached_result is not None: + self.inference_result_signal.emit(self.cached_result) if self.once_mode: self._running = False break @@ -74,7 +76,10 @@ class InferenceWorkerThread(QThread): self.last_inference_time = current_time self.last_frame = frame.copy() self.cached_result = result - self.inference_result_signal.emit(result) + + # 只有在結果不為 None 時才發送信號 + if result is not None: + self.inference_result_signal.emit(result) if self.once_mode: self._running = False diff --git a/src/views/mainWindows.py b/src/views/mainWindows.py index 7182757..dc586b0 100644 --- a/src/views/mainWindows.py +++ b/src/views/mainWindows.py @@ -204,6 +204,11 @@ class MainWindow(QWidget): def handle_inference_result(self, result): """處理來自推論工作器的結果""" try: + # 如果結果為 None,直接返回不處理 + if result is None: + print("收到空的推論結果 (None),略過處理") + return + # 輸出結果到控制台 print("收到推論結果:", result) @@ -251,7 +256,13 @@ class MainWindow(QWidget): # 不需要顯示彈窗,因為邊界框會直接繪製在畫面上 return - # 對於非邊界框結果,使用彈窗顯示 + # 對於非邊界框結果,使用彈窗顯示 (限制每次只顯示一個彈窗) + # 檢查是否有其他消息框正在顯示 + for widget in QApplication.topLevelWidgets(): + if isinstance(widget, QMessageBox) and widget.isVisible(): + print("已有彈窗顯示中,跳過此次結果顯示") + return + # 創建QMessageBox msgBox = QMessageBox(self) msgBox.setWindowTitle("推論結果") diff --git a/update_diary.md b/update_diary.md index 30a83ba..30ce266 100644 --- a/update_diary.md +++ b/update_diary.md @@ -19,4 +19,14 @@ "results": ["label1", "label2"] } ``` -5. 更新 README.md: 添加 bounding boxes 的 return value \ No newline at end of file +5. 更新 README.md: 添加 bounding boxes 的 return value +#### total: 3.5 hrs + +### 0415 +1. 尋找 Face detection and Face recognition's pretrained model +#### total: 1 hrs + +### 0416 +1. 將 arcface's pth model 轉換成 onnx +2. 修正 video inference return none 導致的 crash +#### total: 3 hrs \ No newline at end of file