更新readme

This commit is contained in:
scout 2024-12-04 16:05:47 +08:00
parent b186773a12
commit 9494448ea3
3 changed files with 29 additions and 21 deletions

View File

@ -1,4 +1,4 @@
# 离开自动锁屏系统 # 工位监控系统
## 安装步骤 ## 安装步骤
@ -7,7 +7,12 @@
- 下载并安装 Python 3.10 - 下载并安装 Python 3.10
- 安装时请勾选 "Add Python to PATH" - 安装时请勾选 "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 - 双击运行 start.bat
- 首次运行时会自动安装所需的依赖包 - 首次运行时会自动安装所需的依赖包
- 等待程序启动 - 等待程序启动
@ -18,15 +23,19 @@
- 重新安装Python确保勾选"Add Python to PATH" - 重新安装Python确保勾选"Add Python to PATH"
- 或者重启电脑 - 或者重启电脑
2. 如果摄像头无法打开 2. 如果遇到DLL错误
- 安装 Visual C++ Redistributable见上方安装步骤2
- 如果还有问题,尝试重启电脑
3. 如果摄像头无法打开
- 确保摄像头已正确连接 - 确保摄像头已正确连接
- 确保没有其他程序正在使用摄像头 - 确保没有其他程序正在使用摄像头
- 检查摄像头驱动是否正确安装 - 检查摄像头驱动是否正确安装
3. 如果依赖包安装失败 4. 如果依赖包安装失败
- 确保电脑连接到互联网 - 确保电脑连接到互联网
- 尝试以管理员身份运行start.bat - 尝试以管理员身份运行start.bat
## 联系方式 ## 联系方式
made by scout 如有问题请联系管理员。

View File

@ -12,11 +12,12 @@ if errorlevel 1 (
echo Installing/Updating pip... echo Installing/Updating pip...
python -m pip install --upgrade pip python -m pip install --upgrade pip
echo Installing requirements one by one... echo Installing wheel and setuptools...
echo Installing OpenCV... 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 python -m pip install opencv-python==4.8.1.78
echo Installing PyQt5...
python -m pip install PyQt5==5.15.9
echo Starting application... echo Starting application...
python workspace_monitor.py python workspace_monitor.py

View File

@ -241,8 +241,8 @@ try:
cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2) cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)
# 显示置信度 # 显示置信度
cv2.putText(frame, f"置信度: {max_confidence:.2f}", cv2.putText(frame, f"置信度: {max_confidence:.2f}",
(x, y-10), cv2.FONT_HERSHEY_SIMPLEX, (x, y-10), cv2.FONT_HERSHEY_SIMPLEX,
0.5, (0, 255, 0), 2) 0.5, (0, 255, 0), 2)
self.last_face_time = current_time self.last_face_time = current_time
self.no_face_duration = 0 self.no_face_duration = 0
@ -285,7 +285,7 @@ try:
rgb_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) rgb_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
h, w, ch = rgb_frame.shape h, w, ch = rgb_frame.shape
bytes_per_line = ch * w 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( scaled_pixmap = QPixmap.fromImage(qt_image).scaled(
self.camera_label.size(), self.camera_label.size(),
Qt.KeepAspectRatio Qt.KeepAspectRatio
@ -307,7 +307,6 @@ try:
self.status_label.setText("状态: 正在监控") self.status_label.setText("状态: 正在监控")
self.timer.start(30) self.timer.start(30)
self.tray_icon.showMessage("工位监控", "监控已开始", QSystemTrayIcon.Information) self.tray_icon.showMessage("工位监控", "监控已开始", QSystemTrayIcon.Information)
self.tray_icon.showMessage("工位监控", "监控已开始", QSystemTrayIcon.MessageIcon.Information)
else: else:
self.running = False self.running = False
self.start_stop_btn.setText("开始监控") self.start_stop_btn.setText("开始监控")
@ -321,7 +320,7 @@ try:
self.progress_bar.setFormat("离开时间: 0s") self.progress_bar.setFormat("离开时间: 0s")
self.set_progress_bar_style("#4CAF50") # 重置进度条颜色为绿色 self.set_progress_bar_style("#4CAF50") # 重置进度条颜色为绿色
self.confidence_label.setText("置信度: 0%") self.confidence_label.setText("置信度: 0%")
self.tray_icon.showMessage("工位监控", "监控已停止", QSystemTrayIcon.MessageIcon.Information) self.tray_icon.showMessage("工位监控", "监控已停止", QSystemTrayIcon.Information)
def update_timeout(self, value): def update_timeout(self, value):
self.timeout = value self.timeout = value
@ -332,7 +331,7 @@ try:
def closeEvent(self, event): def closeEvent(self, event):
if self.running: if self.running:
self.tray_icon.showMessage("工位监控", "程序已最小化到系统托盘", self.tray_icon.showMessage("工位监控", "程序已最小化到系统托盘",
QSystemTrayIcon.MessageIcon.Information) QSystemTrayIcon.Information)
self.hide() self.hide()
event.ignore() event.ignore()
else: else:
@ -355,7 +354,7 @@ try:
self.tray_icon.showMessage( self.tray_icon.showMessage(
"工位监控", "工位监控",
"摄像头已断开,监控已停止", "摄像头已断开,监控已停止",
QSystemTrayIcon.MessageIcon.Warning QSystemTrayIcon.Warning
) )
# 尝试重新打开摄像头 # 尝试重新打开摄像头
@ -379,7 +378,7 @@ try:
self.tray_icon.showMessage( self.tray_icon.showMessage(
"工位监控", "工位监控",
"摄像头已重新连接,请手动开启监控", "摄像头已重新连接,请手动开启监控",
QSystemTrayIcon.MessageIcon.Information QSystemTrayIcon.Information
) )
def set_progress_bar_style(self, color="#4CAF50"): def set_progress_bar_style(self, color="#4CAF50"):
@ -408,7 +407,7 @@ try:
window = WorkspaceMonitor() window = WorkspaceMonitor()
window.show() window.show()
logger.info("Application started successfully.") logger.info("Application started successfully.")
sys.exit(app.exec()) sys.exit(app.exec_())
except Exception as e: except Exception as e:
logger.error(f"Error in main function: {str(e)}") logger.error(f"Error in main function: {str(e)}")
logger.error(traceback.format_exc()) logger.error(traceback.format_exc())
@ -423,14 +422,13 @@ try:
# 显示错误消息框 # 显示错误消息框
if QApplication.instance() is None: if QApplication.instance() is None:
app = QApplication(sys.argv) app = QApplication(sys.argv)
from PyQt6.QtWidgets import QMessageBox
msg = QMessageBox() msg = QMessageBox()
msg.setIcon(QMessageBox.Icon.Critical) msg.setIcon(QMessageBox.Critical)
msg.setText("程序发生错误") msg.setText("程序发生错误")
msg.setInformativeText(str(e)) msg.setInformativeText(str(e))
msg.setWindowTitle("错误") msg.setWindowTitle("错误")
msg.setDetailedText(traceback.format_exc()) msg.setDetailedText(traceback.format_exc())
msg.exec() msg.exec_()
sys.exit(1) sys.exit(1)
except Exception as e: except Exception as e: