new cool detection dis/enable
All checks were successful
Build MuCaPy Executable / build-and-package (push) Successful in 1m44s
All checks were successful
Build MuCaPy Executable / build-and-package (push) Successful in 1m44s
This commit is contained in:
@@ -13,7 +13,7 @@ from PyQt5.QtWidgets import (QApplication, QMainWindow, QVBoxLayout, QHBoxLayout
|
||||
QShortcut, QListWidget, QFormLayout, QLineEdit,
|
||||
QCheckBox, QTabWidget, QListWidgetItem, QSplitter,
|
||||
QProgressBar) # Add QProgressBar
|
||||
from PyQt5.QtCore import Qt, QTimer, QDir, QSize, QSettings, QDateTime, QRect, QThread, pyqtSignal, QMutex
|
||||
from PyQt5.QtCore import Qt, QTimer, QDir, QSize, QSettings, QDateTime, QRect, QThread, pyqtSignal, QMutex, QObject
|
||||
from PyQt5.QtGui import (QImage, QPixmap, QIcon, QColor, QKeySequence, QPainter,
|
||||
QPen, QBrush)
|
||||
import time
|
||||
@@ -301,8 +301,9 @@ class CameraThread(QThread):
|
||||
self.cap.release()
|
||||
self.running = False
|
||||
|
||||
class MultiCamYOLODetector:
|
||||
def __init__(self):
|
||||
class MultiCamYOLODetector(QObject):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
self.cameras = []
|
||||
self.camera_threads = {} # Dictionary to store camera threads
|
||||
self.net = None
|
||||
@@ -489,6 +490,9 @@ class MultiCamYOLODetector:
|
||||
print(f"Warning: Could not read frame from camera {cam_path}")
|
||||
frame = np.zeros((720, 1280, 3), dtype=np.uint8)
|
||||
else:
|
||||
# Only perform detection if net is loaded and detection is requested
|
||||
parent_window = self.parent()
|
||||
if parent_window and self.net is not None and parent_window.detection_enabled:
|
||||
frame = self.get_detections(frame)
|
||||
frames.append(frame)
|
||||
except:
|
||||
@@ -1319,8 +1323,9 @@ class MainWindow(QMainWindow):
|
||||
|
||||
# Initialize default values
|
||||
self.current_layout = 0 # Default to single camera layout
|
||||
self.detector = MultiCamYOLODetector()
|
||||
self.detector = MultiCamYOLODetector(self) # Pass self as parent
|
||||
self.camera_settings = {}
|
||||
self.detection_enabled = True # Add detection toggle flag
|
||||
|
||||
# Load saved settings first
|
||||
self.load_saved_settings()
|
||||
@@ -1525,6 +1530,14 @@ class MainWindow(QMainWindow):
|
||||
self.toggle_sidebar_action.triggered.connect(self.toggle_sidebar_visibility)
|
||||
view_menu.addAction(self.toggle_sidebar_action)
|
||||
|
||||
# Add toggle detection action
|
||||
self.toggle_detection_action = QAction('Enable Detection', self)
|
||||
self.toggle_detection_action.setCheckable(True)
|
||||
self.toggle_detection_action.setChecked(True)
|
||||
self.toggle_detection_action.setShortcut('Ctrl+D')
|
||||
self.toggle_detection_action.triggered.connect(self.toggle_detection)
|
||||
view_menu.addAction(self.toggle_detection_action)
|
||||
|
||||
# Camera menu
|
||||
self.camera_menu = menubar.addMenu('Cameras')
|
||||
|
||||
@@ -2221,6 +2234,16 @@ class MainWindow(QMainWindow):
|
||||
}
|
||||
""")
|
||||
|
||||
def toggle_detection(self):
|
||||
"""Toggle detection enabled/disabled"""
|
||||
self.detection_enabled = self.toggle_detection_action.isChecked()
|
||||
if self.detection_enabled:
|
||||
self.start_btn.setEnabled(True)
|
||||
self.stop_btn.setEnabled(True)
|
||||
else:
|
||||
self.start_btn.setEnabled(False)
|
||||
self.stop_btn.setEnabled(False)
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = QApplication(sys.argv)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user