From 9494448ea3d00f2972a0fcce25df657aa7bb0274 Mon Sep 17 00:00:00 2001 From: scout <1134087124@qq.com> Date: Wed, 4 Dec 2024 16:05:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0readme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 19 ++++++++++++++----- start.bat | 9 +++++---- workspace_monitor.py | 22 ++++++++++------------ 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index b18e9df..77cba8d 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# 离开自动锁屏系统 +# 工位监控系统 ## 安装步骤 @@ -7,7 +7,12 @@ - 下载并安装 Python 3.10 - 安装时请勾选 "Add Python to PATH" -2. 运行程序 +2. 安装 Visual C++ Redistributable(如果遇到DLL错误) + - 下载 [Visual C++ Redistributable](https://aka.ms/vs/17/release/vc_redist.x64.exe) + - 运行安装程序 + - 按照提示完成安装 + +3. 运行程序 - 双击运行 start.bat - 首次运行时会自动安装所需的依赖包 - 等待程序启动 @@ -18,15 +23,19 @@ - 重新安装Python,确保勾选"Add Python to PATH" - 或者重启电脑 -2. 如果摄像头无法打开 +2. 如果遇到DLL错误 + - 安装 Visual C++ Redistributable(见上方安装步骤2) + - 如果还有问题,尝试重启电脑 + +3. 如果摄像头无法打开 - 确保摄像头已正确连接 - 确保没有其他程序正在使用摄像头 - 检查摄像头驱动是否正确安装 -3. 如果依赖包安装失败 +4. 如果依赖包安装失败 - 确保电脑连接到互联网 - 尝试以管理员身份运行start.bat ## 联系方式 -made by scout \ No newline at end of file +如有问题请联系管理员。 \ No newline at end of file diff --git a/start.bat b/start.bat index 507e50d..3173767 100644 --- a/start.bat +++ b/start.bat @@ -12,11 +12,12 @@ if errorlevel 1 ( echo Installing/Updating pip... python -m pip install --upgrade pip -echo Installing requirements one by one... -echo Installing OpenCV... +echo Installing wheel and setuptools... +python -m pip install --upgrade wheel setuptools + +echo Installing requirements from binary packages... +python -m pip install --only-binary :all: PyQt5==5.15.9 python -m pip install opencv-python==4.8.1.78 -echo Installing PyQt5... -python -m pip install PyQt5==5.15.9 echo Starting application... python workspace_monitor.py diff --git a/workspace_monitor.py b/workspace_monitor.py index 5f4cbd3..2a634f4 100644 --- a/workspace_monitor.py +++ b/workspace_monitor.py @@ -241,8 +241,8 @@ try: cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2) # 显示置信度 cv2.putText(frame, f"置信度: {max_confidence:.2f}", - (x, y-10), cv2.FONT_HERSHEY_SIMPLEX, - 0.5, (0, 255, 0), 2) + (x, y-10), cv2.FONT_HERSHEY_SIMPLEX, + 0.5, (0, 255, 0), 2) self.last_face_time = current_time self.no_face_duration = 0 @@ -285,7 +285,7 @@ try: rgb_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) h, w, ch = rgb_frame.shape bytes_per_line = ch * w - qt_image = QImage(rgb_frame.data, w, h, bytes_per_line, QImage.Format.RGB888) + qt_image = QImage(rgb_frame.data, w, h, bytes_per_line, QImage.Format_RGB888) scaled_pixmap = QPixmap.fromImage(qt_image).scaled( self.camera_label.size(), Qt.KeepAspectRatio @@ -307,7 +307,6 @@ try: self.status_label.setText("状态: 正在监控") self.timer.start(30) self.tray_icon.showMessage("工位监控", "监控已开始", QSystemTrayIcon.Information) - self.tray_icon.showMessage("工位监控", "监控已开始", QSystemTrayIcon.MessageIcon.Information) else: self.running = False self.start_stop_btn.setText("开始监控") @@ -321,7 +320,7 @@ try: self.progress_bar.setFormat("离开时间: 0s") self.set_progress_bar_style("#4CAF50") # 重置进度条颜色为绿色 self.confidence_label.setText("置信度: 0%") - self.tray_icon.showMessage("工位监控", "监控已停止", QSystemTrayIcon.MessageIcon.Information) + self.tray_icon.showMessage("工位监控", "监控已停止", QSystemTrayIcon.Information) def update_timeout(self, value): self.timeout = value @@ -332,7 +331,7 @@ try: def closeEvent(self, event): if self.running: self.tray_icon.showMessage("工位监控", "程序已最小化到系统托盘", - QSystemTrayIcon.MessageIcon.Information) + QSystemTrayIcon.Information) self.hide() event.ignore() else: @@ -355,7 +354,7 @@ try: self.tray_icon.showMessage( "工位监控", "摄像头已断开,监控已停止", - QSystemTrayIcon.MessageIcon.Warning + QSystemTrayIcon.Warning ) # 尝试重新打开摄像头 @@ -379,7 +378,7 @@ try: self.tray_icon.showMessage( "工位监控", "摄像头已重新连接,请手动开启监控", - QSystemTrayIcon.MessageIcon.Information + QSystemTrayIcon.Information ) def set_progress_bar_style(self, color="#4CAF50"): @@ -408,7 +407,7 @@ try: window = WorkspaceMonitor() window.show() logger.info("Application started successfully.") - sys.exit(app.exec()) + sys.exit(app.exec_()) except Exception as e: logger.error(f"Error in main function: {str(e)}") logger.error(traceback.format_exc()) @@ -423,14 +422,13 @@ try: # 显示错误消息框 if QApplication.instance() is None: app = QApplication(sys.argv) - from PyQt6.QtWidgets import QMessageBox msg = QMessageBox() - msg.setIcon(QMessageBox.Icon.Critical) + msg.setIcon(QMessageBox.Critical) msg.setText("程序发生错误") msg.setInformativeText(str(e)) msg.setWindowTitle("错误") msg.setDetailedText(traceback.format_exc()) - msg.exec() + msg.exec_() sys.exit(1) except Exception as e: