活动介绍

class MainWindow(QMainWindow): def __init__(self): super().__init__() self.setFixedSize(800, 600) main_layout = QVBoxLayout() central_widget = QWidget() central_widget.setLayout(main_layout) self.setCentralWidget(central_widget) button_layout = QVBoxLayout() button1 = QPushButton('当日员工工资') button1.setFixedSize(200, 50) button1.clicked.connect(self.show_query1_result) button_layout.addStretch() button_layout.addWidget(button1) button_layout.addStretch() layout = QHBoxLayout() layout.addStretch() layout.addLayout(button_layout) layout.addStretch() widget = QWidget() widget.setLayout(layout) self.setCentralWidget(widget) main_layout.addLayout(button_layout) self.query1_window = QueryResultWindow() def show_query1_result(self): db = pymysql.connect(host='39.99.214.172', user='root', password='Solotion.123', db='jj_tset') cursor = db.cursor() db_sql = """ """ cursor.execute(db_sql) result = cursor.fetchall() db.close() if len(result) == 0: QMessageBox.information(self, "提示", "今日无员工工资记录") return self.query1_window.table_widget.setRowCount(0) self.query1_window.table_widget.setColumnCount(len(result[0])) self.query1_window.table_widget.setHorizontalHeaderLabels( ["员工ID", "员工姓名", "日期", "领取鸡爪重量(KG)", "效率(每小时KG)", "出成率", "基础工资", "重量奖励", "当日总工资"]) for row_num, row_data in enumerate(result): self.query1_window.table_widget.insertRow(row_num) for col_num, col_data in enumerate(row_data): self.query1_window.table_widget.setItem(row_num, col_num, QTableWidgetItem(str(col_data))) self.query1_window.show() class QueryResultWindow(QWidget): def __init__(self): super().__init__() self.setFixedSize(800, 600) self.table_widget = QTableWidget() self.table_widget.setEditTriggers(QTableWidget.NoEditTriggers) self.table_widget.setSelectionBehavior(QTableWidget.SelectRows) layout = QVBoxLayout() layout.addWidget(self.table_widget) self.setLayout(layout) if __name__ == '__main__': app = QApplication(sys.argv) loginWindow = LoginWindow() loginWindow.show() sys.exit(app.exec_()))数据展示页面怎么设置筛选器按ID筛选结果并展示

时间: 2023-11-22 21:54:27 浏览: 188
你可以在数据展示页面添加一个QLineEdit和一个QPushButton,让用户输入员工ID并点击按钮进行筛选。 具体实现方法如下: 1. 在QueryResultWindow类的初始化函数中添加以下代码来创建QLineEdit和QPushButton: ``` self.id_line_edit = QLineEdit() self.filter_button = QPushButton('筛选') self.filter_button.clicked.connect(self.filter_result) ``` 2. 在layout中添加这两个控件: ``` layout.addWidget(self.id_line_edit) layout.addWidget(self.filter_button) ``` 3. 添加filter_result函数来执行筛选操作: ``` def filter_result(self): id = self.id_line_edit.text().strip() if len(id) == 0: QMessageBox.warning(self, '提示', '请输入员工ID') return db = pymysql.connect(host='39.99.214.172', user='root', password='Solotion.123', db='jj_tset') cursor = db.cursor() db_sql = f"SELECT * FROM table_name WHERE id = '{id}'" cursor.execute(db_sql) result = cursor.fetchall() db.close() if len(result) == 0: QMessageBox.information(self, "提示", "没有找到符合条件的记录") return self.table_widget.setRowCount(0) for row_num, row_data in enumerate(result): self.table_widget.insertRow(row_num) for col_num, col_data in enumerate(row_data): self.table_widget.setItem(row_num, col_num, QTableWidgetItem(str(col_data))) ``` 注意替换db_sql中的table_name为你的表名。这个函数会从数据库中查询符合条件的记录并展示在表格中。 4. 修改show_query1_result函数,在最开始添加以下代码,用于展示所有记录: ``` db = pymysql.connect(host='39.99.214.172', user='root', password='Solotion.123', db='jj_tset') cursor = db.cursor() db_sql = """SELECT * FROM table_name""" cursor.execute(db_sql) result = cursor.fetchall() db.close() if len(result) == 0: QMessageBox.information(self, "提示", "今日无员工工资记录") return ``` 注意同样替换db_sql中的table_name为你的表名。这个代码块会在进入数据展示页面时展示所有记录。 通过以上修改,你就可以在数据展示页面添加筛选功能了。
阅读全文

相关推荐

class MainWindow(QMainWindow): def __init__(self): super().__init__() self.setWindowTitle("小红书风格布局") self.posts = [] self.current_cols = 5 self.animations = [] # 创建滚动区域 scroll_area = QScrollArea() scroll_area.setWidgetResizable(True) self.central_content = QWidget() scroll_area.setWidget(self.central_content) self.setCentralWidget(scroll_area) # 初始化样式参数 self.post_width = 240 self.post_height = 320 self.spacing = 15 self.margins = (20, 20, 20, 20) # 生成示例内容 for i in range(10): post = SocialMediaPost(f"{i+9}.jpg", f"精选好物推荐 #{i+1}") post.setFixedSize(self.post_width, self.post_height) post.setParent(self.central_content) self.posts.append(post) self.central_content.setContentsMargins(*self.margins) self.rearrange_posts() def resizeEvent(self, event): super().resizeEvent(event) self.rearrange_posts() def rearrange_posts(self): # 停止正在进行的动画 for anim in self.animations: anim.stop() self.animations.clear() # 计算可用宽度 viewport_width = self.centralWidget().viewport().width() available_width = viewport_width - (self.margins[0] + self.margins[2]) # 动态计算列数 cols = self.calculate_columns(available_width) if cols == self.current_cols: return self.current_cols = cols # 计算布局参数 rows = (len(self.posts) + cols - 1) // cols content_width = cols * (self.post_width + self.spacing) - self.spacing content_height = rows * (self.post_height + self.spacing) - self.spacing self.central_content.setMinimumSize(content_width + self.margins[0] + self.margins[2], content_height + self.margins[1] + self.margins[3]) # 生成动画 for i, post in enumerate(self.posts): row = i // cols col = i % cols target_x = col * (self.post_width + self.spacing) target_y = row * (self.post_height + self.spacing) anim = QPropertyAnimation(post, b"geometry") anim.setDuration(400) anim.setEasingCurve(QEasingCurve.OutQuad) anim.setStartValue(post.geometry()) anim.setEndValue(QRect(target_x, target_y, self.post_width, self.post_height)) self.animations.append(anim) anim.start() def calculate_columns(self, available_width): max_cols = 5 for cols in range(max_cols, 0, -1): required = cols * self.post_width + (cols-1)*self.spacing if required <= available_width: return cols return 1 class SocialMediaPost(QWidget): def __init__(self, image_path, title): super().__init__() # 这里实现具体的帖子UI组件 # 示例样式设置 self.setStyleSheet(""" background: white; border-radius: 8px; padding: 10px; """)用pyside6重写这段代码

import keyboard import pyautogui import win32gui import pyperclip from datetime import datetime import os from PyQt5.QtGui import QIcon from PyQt5.QtWidgets import (QApplication, QMainWindow, QWidget, QVBoxLayout, QLabel, QSpinBox, QFrame, QHBoxLayout, QRadioButton, QButtonGroup, QPushButton) from PyQt5.QtCore import Qt, QThread, pyqtSignal import sys import time import win32con class MonitorThread(QThread): update_signal = pyqtSignal(int) finished_signal = pyqtSignal() error_signal = pyqtSignal(str) def __init__(self, total_times, is_priority): super().__init__() self.total_times = total_times self.running = True self.is_priority = is_priority def check_edge_window(self): active_window = win32gui.GetForegroundWindow() window_title = win32gui.GetWindowText(active_window) if "Edge" not in window_title: return False, "请将Edge浏览器窗口置于最前" placement = win32gui.GetWindowPlacement(active_window) is_maximized = placement[1] == win32con.SW_SHOWMAXIMIZED if not is_maximized: return False, "请将Edge浏览器窗口最大化" return True, "" def run(self): count = 0 while count < self.total_times and self.running: is_valid, error_msg = self.check_edge_window() if not is_valid: self.error_signal.emit(error_msg) time.sleep(1) continue pyautogui.moveTo(300, 50) pyautogui.click() pyautogui.hotkey('ctrl', 'l') time.sleep(0.1) pyautogui.hotkey('ctrl', 'c') time.sleep(0.1) url = pyperclip.paste() today = datetime.now().strftime('%Y%m%d') file_type = '优先' if self.is_priority else '稍后' file_path = os.path.join(r'D:\Desk\记录\TXT\EdgeURL', f'{today}_{file_type}.txt') os.makedirs(os.path.dirname(file_path), exist_ok=True) exists = False if os.path.exists(file_path): with open(file_path, 'r', encoding='utf-8') as f: if url in f.read(): exists = True if not exists and url.startswith('http'): with open(file_path, 'a', encoding='utf-8') as f: f.write(url + '\n') pyautogui.hotkey('ctrl', 'w') time.sleep(0.1) count += 1 self.update_signal.emit(count) time.sleep(0.01) if keyboard.is_pressed('esc'): self.running = False break self.finished_signal.emit() class MainWindow(QMainWindow): def __init__(self): super().__init__() self.init_ui() self.monitor_thread = None def init_ui(self): self.setWindowTitle('Edge URL监控器') self.setWindowIcon(QIcon('./URL.png')) self.setFixedSize(450, 240) self.setStyleSheet(""" QMainWindow { background-color: #f0f2f5; } QLabel { font-size: 16px; font-weight: bold; } QSpinBox { padding: 10px; border: 2px solid #1890ff; border-radius: 8px; font-size: 20px; min-height: 40px; min-width: 120px; } QSpinBox::up-button, QSpinBox::down-button { width: 30px; height: 20px; } QSpinBox::up-button { subcontrol-position: top right; } QSpinBox::down-button { subcontrol-position: bottom right; } QRadioButton { font-size: 18px; padding: 8px 15px; margin: 5px 10px; min-width: 100px; min-height: 40px; } QRadioButton::indicator { width: 20px; height: 20px; margin-right: 8px; } QRadioButton:hover { background-color: #e6f7ff; border-radius: 5px; } QRadioButton:checked { color: #1890ff; font-weight: bold; } """) central_widget = QWidget() self.setCentralWidget(central_widget) layout = QVBoxLayout(central_widget) layout.setContentsMargins(20, 20, 20, 20) layout.setSpacing(20) frame = QFrame() frame_layout = QVBoxLayout(frame) frame_layout.setSpacing(20) count_layout = QHBoxLayout() self.count_label = QLabel('执行次数:') self.count_spinbox = QSpinBox() self.count_spinbox.setRange(1, 999999) self.count_spinbox.setValue(1) count_layout.addWidget(self.count_label) count_layout.addWidget(self.count_spinbox) count_layout.addStretch() option_layout = QHBoxLayout() option_layout.setSpacing(15) self.option_label = QLabel('保存选项:') self.priority_group = QButtonGroup() self.priority_radio = QRadioButton('优先') self.later_radio = QRadioButton('稍后') self.priority_radio.setChecked(True) self.priority_group.addButton(self.priority_radio) self.priority_group.addButton(self.later_radio) option_layout.addWidget(self.option_label) option_layout.addWidget(self.priority_radio) option_layout.addWidget(self.later_radio) option_layout.addStretch() status_layout = QHBoxLayout() self.status_label = QLabel('状态: 等待开始 (按F9开始执行)') self.status_label.setStyleSheet(""" QLabel { font-size: 16px; color: #1890ff; } """) self.progress_label = QLabel('进度: 0/0') self.progress_label.setStyleSheet(""" QLabel { font-size: 16px; color: #52c41a; } """) self.stop_button = QPushButton('停止') self.stop_button.setStyleSheet(""" QPushButton { background-color: #ff4d4f; color: white; border: none; border-radius: 8px; padding: 8px 20px; font-size: 16px; min-width: 100px; } QPushButton:hover { background-color: #ff7875; } QPushButton:pressed { background-color: #d9363e; } """) self.stop_button.setEnabled(False) self.stop_button.clicked.connect(self.stop_monitoring) status_layout.addWidget(self.status_label) status_layout.addWidget(self.progress_label) status_layout.addWidget(self.stop_button) status_layout.addStretch() frame_layout.addLayout(count_layout) frame_layout.addLayout(option_layout) frame_layout.addLayout(status_layout) frame_layout.addStretch() layout.addWidget(frame) self.setWindowFlags(self.windowFlags() | Qt.WindowStaysOnTopHint) keyboard.on_press_key('F9', self.start_monitoring) def start_monitoring(self, _): if not self.monitor_thread or not self.monitor_thread.isRunning(): self.status_label.setText('状态: 正在执行 (按ESC停止)') total_times = self.count_spinbox.value() is_priority = self.priority_radio.isChecked() self.monitor_thread = MonitorThread(total_times, is_priority) self.monitor_thread.update_signal.connect(self.update_progress) self.monitor_thread.finished_signal.connect(self.monitoring_finished) self.monitor_thread.error_signal.connect(self.show_error) self.monitor_thread.start() self.stop_button.setEnabled(True) def update_progress(self, count): total = self.count_spinbox.value() self.progress_label.setText(f'进度: {count}/{total}') def stop_monitoring(self): if self.monitor_thread and self.monitor_thread.isRunning(): self.monitor_thread.running = False self.monitor_thread.wait() self.monitoring_finished() self.stop_button.setEnabled(False) def monitoring_finished(self): self.status_label.setText('状态: 等待开始 (按F9开始执行)') self.progress_label.setText('进度: 0/0') self.stop_button.setEnabled(False) def show_error(self, message): self.status_label.setText(f'状态: {message}') def closeEvent(self, event): if self.monitor_thread and self.monitor_thread.isRunning(): self.monitor_thread.running = False self.monitor_thread.wait() keyboard.unhook_all() event.accept() def main(): app = QApplication(sys.argv) window = MainWindow() window.show() sys.exit(app.exec_()) if __name__ == '__main__': main() 在这个优先,稍后 基础上再加上第三个选项‘金币’

import sys import math import random from PyQt5.QtWidgets import (QApplication, QWidget, QLabel, QVBoxLayout, QHBoxLayout, QMainWindow) from PyQt5.QtGui import QPainter, QPen, QBrush, QColor, QFont from PyQt5.QtCore import Qt, QRectF, QTimer, QPointF class AttitudeIndicator(QWidget): def __init__(self, title, parent=None, size=100): super(AttitudeIndicator, self).__init__(parent) self.title = title self.angle = 0 self.size = size # 存储目标尺寸 self.initUI() def initUI(self): # 设置固定尺寸为100x120像素(仪表盘100x100 + 标签20像素) self.setFixedSize(self.size, self.size + 20) # 创建布局并添加标签 self.layout = QVBoxLayout() self.layout.setSpacing(0) self.layout.setContentsMargins(0, 0, 0, 0) # 移除所有边距 # 添加标签 self.label = QLabel(self.title) self.label.setAlignment(Qt.AlignCenter) self.label.setFixedHeight(10) # 固定标签高度 self.layout.addWidget(self.label) self.setLayout(self.layout) def set_angle(self, angle): self.angle = angle % 360 self.update() def get_angle(self): return self.angle def paintEvent(self, event): painter = QPainter(self) painter.setRenderHint(QPainter.Antialiasing) # 计算仪表盘区域(100x100像素) gauge_size = self.size center_x = self.width() / 2 center_y = gauge_size / 2 # 仪表盘中心在100像素区域中心 # 仪表盘半径(基于固定尺寸) radius = gauge_size / 2 * 0.9 # 保留10%边距 # 绘制仪表盘背景 painter.setBrush(QBrush(QColor(240, 240, 240))) painter.drawEllipse(center_x - radius, center_y - radius, radius * 2, radius * 2) # 绘制外边框 painter.setPen(QPen(Qt.black, 2)) painter.drawEllipse(center_x - radius, center_y - radius, radius * 2, radius * 2) # 绘制刻度 painter.setPen(QPen(Qt.black, 1)) font = QFont("Arial", max(8, int(radius * 0.1))) painter.setFont(font) for i in range(0, 360, 30): angle_rad = math.radians(i) # 计算刻度位置 inner_x = center_x + (radius * 0.85) * math.sin(angle_rad) inner_y = center_y - (radius * 0.85) * math.cos(angle_rad) outer_x = center_x + radius * math.sin(angle_rad) outer_y = center_y - radius * math.cos(angle_rad) # 绘制刻度线 painter.drawLine(inner_x, inner_y, outer_x, outer_y) # 绘制刻度值(主要刻度) if i % 90 == 0: text_x = center_x + (radius * 0.7) * math.sin(angle_rad) text_y = center_y - (radius * 0.7) * math.cos(angle_rad) painter.drawText(text_x - 10, text_y - 5, 20, 10, Qt.AlignCenter, str(i)) # 绘制指针 pointer_angle_rad = math.radians(self.angle) painter.setPen(QPen(Qt.red, 2)) # 指针起点为中心点 start_point = QPointF(center_x, center_y) # 指针终点(长度为半径的80%) end_x = center_x + radius * 0.8 * math.sin(pointer_angle_rad) end_y = center_y - radius * 0.8 * math.cos(pointer_angle_rad) end_point = QPointF(end_x, end_y) painter.drawLine(start_point, end_point) # 绘制中心点 painter.setBrush(QBrush(Qt.red)) painter.drawEllipse(center_x - 3, center_y - 3, 6, 6) # 显示当前角度值 angle_text = f"{self.angle:.1f}°" painter.setPen(Qt.blue) painter.drawText(center_x - 20, center_y + radius * 0.3, 40, 20, Qt.AlignCenter, angle_text) class InertialNavigationWidget(QWidget): def __init__(self, parent=None): super(InertialNavigationWidget, self).__init__(parent) self.initUI() def initUI(self): self.setWindowTitle("姿态显示") self.setMinimumSize(500, 200) # 创建三个姿态指示器(大小为100像素) self.pitch_indicator = AttitudeIndicator("俯仰角", size=100) self.roll_indicator = AttitudeIndicator("横倾角", size=100) self.yaw_indicator = AttitudeIndicator("航向角", size=100) # 设置布局 layout = QHBoxLayout() layout.addWidget(self.pitch_indicator) layout.addWidget(self.roll_indicator) layout.addWidget(self.yaw_indicator) self.setLayout(layout) # 创建定时器更新姿态数据 self.timer = QTimer(self) self.timer.timeout.connect(self.update_attitude) self.timer.start(1000) # 1秒更新一次 def update_attitude(self): # 模拟从惯导设备获取实时数据 pitch = random.uniform(0, 360) roll = random.uniform(0, 360) yaw = random.uniform(0, 360) # 更新指示器 self.pitch_indicator.set_angle(pitch) self.roll_indicator.set_angle(roll) self.yaw_indicator.set_angle(yaw) class MainWindow(QMainWindow): def __init__(self): super().__init__() self.setWindowTitle("飞行姿态仪表盘") self.setGeometry(100, 100, 600, 300) # 创建主部件 self.inertial_widget = InertialNavigationWidget() self.setCentralWidget(self.inertial_widget) if __name__ == "__main__": app = QApplication(sys.argv) window = MainWindow() window.show() sys.exit(app.exec_()) 请帮我将仪表盘的名字放在仪表盘的下方,不要放在仪表盘的内部 再将显示当前角度值,的数字调小两号

class MainWindow(QMainWindow): def init(self): super().init() self.setFixedSize(800, 600) main_layout = QVBoxLayout() central_widget = QWidget() central_widget.setLayout(main_layout) self.setCentralWidget(central_widget) button_layout = QVBoxLayout() button1 = QPushButton('当日员工工资') button1.setFixedSize(200, 50) button1.clicked.connect(self.show_query1_result) button_layout.addStretch() button_layout.addWidget(button1) button_layout.addStretch() layout = QHBoxLayout() layout.addStretch() layout.addLayout(button_layout) layout.addStretch() widget = QWidget() widget.setLayout(layout) self.setCentralWidget(widget) main_layout.addLayout(button_layout) self.query1_window = QueryResultWindow() def show_query1_result(self): db = pymysql.connect(host='39.99.214.172', user='root', password='Solotion.123', db='jj_tset') cursor = db.cursor() db_sql = """ """ cursor.execute(db_sql) result = cursor.fetchall() db.close() if len(result) == 0: QMessageBox.information(self, "提示", "今日无员工工资记录") return self.query1_window.table_widget.setRowCount(0) self.query1_window.table_widget.setColumnCount(len(result[0])) self.query1_window.table_widget.setHorizontalHeaderLabels( ["员工ID", "员工姓名", "日期", "领取鸡爪重量(KG)", "效率(每小时KG)", "出成率", "基础工资", "重量奖励", "当日总工资"]) for row_num, row_data in enumerate(result): self.query1_window.table_widget.insertRow(row_num) for col_num, col_data in enumerate(row_data): self.query1_window.table_widget.setItem(row_num, col_num, QTableWidgetItem(str(col_data))) self.query1_window.show() class QueryResultWindow(QWidget): def init(self): super().init() self.setFixedSize(800, 600) self.table_widget = QTableWidget() self.table_widget.setEditTriggers(QTableWidget.NoEditTriggers) self.table_widget.setSelectionBehavior(QTableWidget.SelectRows) layout = QVBoxLayout() layout.addWidget(self.table_widget) self.setLayout(layout) if name == 'main': app = QApplication(sys.argv) loginWindow = LoginWindow() loginWindow.show() sys.exit(app.exec_()))数据展示页面怎么设置筛选器按ID筛选结果并展示的整体代码

我运行这个程序放了标准样本后我不管往这个镜头面前换了啥东西,界面里的实时匹配数据还是纹丝不动而且还是5000%我根本无法知道有没有与标准样本进行比对 # -*- coding: utf-8 -*- import sys import os import cv2 import numpy as np import math import time import logging import threading from collections import deque from PyQt5.QtWidgets import ( QApplication, QMainWindow, QPushButton, QWidget, QVBoxLayout, QHBoxLayout, QMessageBox, QLabel, QFileDialog, QToolBox, QComboBox, QStatusBar, QGroupBox, QSlider, QDockWidget, QProgressDialog, QLineEdit, QRadioButton, QGridLayout, QSpinBox, QCheckBox, QDialog, QDialogButtonBox, QDoubleSpinBox, QProgressBar, ) from PyQt5.QtCore import QRect, Qt, QSettings, QThread, pyqtSignal, QTimer, QMetaObject, pyqtSlot,Q_ARG from PyQt5.QtGui import QImage, QPixmap from CamOperation_class import CameraOperation from MvCameraControl_class import * import ctypes from ctypes import cast, POINTER from datetime import datetime import skimage import platform from CameraParams_header import ( MV_GIGE_DEVICE, MV_USB_DEVICE, MV_GENTL_CAMERALINK_DEVICE, MV_GENTL_CXP_DEVICE, MV_GENTL_XOF_DEVICE ) # ===== 全局配置 ===== # 模板匹配参数 MATCH_THRESHOLD = 0.75 # 降低匹配置信度阈值以提高灵敏度 MIN_MATCH_COUNT = 10 # 最小匹配特征点数量 MIN_FRAME_INTERVAL = 0.1 # 最小检测间隔(秒) # ===== 全局变量 ===== current_sample_path = "" detection_history = [] isGrabbing = False isOpen = False obj_cam_operation = None frame_monitor_thread = None template_matcher_thread = None MV_OK = 0 MV_E_CALLORDER = -2147483647 # ==================== 优化后的质量检测算法 ==================== def enhanced_check_print_quality(sample_image_path, test_image, threshold=0.05): # 不再使用传感器数据调整阈值 adjusted_threshold = threshold try: sample_img_data = np.fromfile(sample_image_path, dtype=np.uint8) sample_image = cv2.imdecode(sample_img_data, cv2.IMREAD_GRAYSCALE) if sample_image is None: logging.error(f"无法解码样本图像: {sample_image_path}") return None, None, None except Exception as e: logging.exception(f"样本图像读取异常: {str(e)}") return None, None, None if len(test_image.shape) == 3: test_image_gray = cv2.cvtColor(test_image, cv2.COLOR_BGR2GRAY) else: test_image_gray = test_image.copy() sample_image = cv2.GaussianBlur(sample_image, (5, 5), 0) test_image_gray = cv2.GaussianBlur(test_image_gray, (5, 5), 0) try: # 使用更鲁棒的SIFT特征检测器 sift = cv2.SIFT_create() keypoints1, descriptors1 = sift.detectAndCompute(sample_image, None) keypoints2, descriptors2 = sift.detectAndCompute(test_image_gray, None) if descriptors1 is None or descriptors2 is None: logging.warning("无法提取特征描述符,跳过配准") aligned_sample = sample_image else: # 使用FLANN匹配器提高匹配精度 FLANN_INDEX_KDTREE = 0 index_params = dict(algorithm=FLANN_INDEX_KDTREE, trees=5) search_params = dict(checks=50) flann = cv2.FlannBasedMatcher(index_params, search_params) matches = flann.knnMatch(descriptors1, descriptors2, k=2) # 应用Lowe's比率测试筛选优质匹配 good_matches = [] for m, n in matches: if m.distance < 0.7 * n.distance: good_matches.append(m) if len(good_matches) > MIN_MATCH_COUNT: src_pts = np.float32([keypoints1[m.queryIdx].pt for m in good_matches]).reshape(-1, 1, 2) dst_pts = np.float32([keypoints2[m.trainIdx].pt for m in good_matches]).reshape(-1, 1, 2) H, mask = cv2.findHomography(src_pts, dst_pts, cv2.RANSAC, 5.0) if H is not None: aligned_sample = cv2.warpPerspective( sample_image, H, (test_image_gray.shape[1], test_image_gray.shape[0]) ) logging.info("图像配准成功,使用配准后样本") else: aligned_sample = sample_image logging.warning("无法计算单应性矩阵,使用原始样本") else: aligned_sample = sample_image logging.warning(f"特征点匹配不足({len(good_matches)}/{MIN_MATCH_COUNT}),跳过图像配准") except Exception as e: logging.error(f"图像配准失败: {str(e)}") aligned_sample = sample_image try: if aligned_sample.shape != test_image_gray.shape: test_image_gray = cv2.resize(test_image_gray, (aligned_sample.shape[1], aligned_sample.shape[0])) except Exception as e: logging.error(f"图像调整大小失败: {str(e)}") return None, None, None try: from skimage.metrics import structural_similarity as compare_ssim ssim_score, ssim_diff = compare_ssim( aligned_sample, test_image_gray, full=True, gaussian_weights=True, data_range=255 ) except ImportError: from skimage.measure import compare_ssim ssim_score, ssim_diff = compare_ssim( aligned_sample, test_image_gray, full=True, gaussian_weights=True ) except Exception as e: logging.error(f"SSIM计算失败: {str(e)}") abs_diff = cv2.absdiff(aligned_sample, test_image_gray) ssim_diff = abs_diff.astype(np.float32) / 255.0 ssim_score = 1.0 - np.mean(ssim_diff) ssim_diff = (1 - ssim_diff) * 255 abs_diff = cv2.absdiff(aligned_sample, test_image_gray) combined_diff = cv2.addWeighted(ssim_diff.astype(np.uint8), 0.7, abs_diff, 0.3, 0) _, thresholded = cv2.threshold(combined_diff, 30, 255, cv2.THRESH_BINARY) kernel = np.ones((3, 3), np.uint8) thresholded = cv2.morphologyEx(thresholded, cv2.MORPH_OPEN, kernel) threshold极光 = cv2.morphologyEx(thresholded, cv2.MORPH_CLOSE, kernel) diff_pixels = np.count_nonzero(thresholded) total_pixels = aligned_sample.size diff_ratio = diff_pixels / total_pixels is_qualified = diff_ratio <= adjusted_threshold marked_image = cv2.cvtColor(test_image_gray, cv2.COLOR_GRAY2BGR) marked_image[thresholded == 255] = [0, 0, 255] # 放大缺陷标记 scale_factor = 2.0 # 放大2倍 marked_image = cv2.resize(marked_image, None, fx=scale_factor, fy=scale_factor, interpolation=cv2.INTER_LINEAR) labels = skimage.measure.label(thresholded) properties = skimage.measure.regionprops(labels) for prop in properties: if prop.area > 50: y, x = prop.centroid # 根据放大比例调整坐标 x_scaled = int(x * scale_factor) y_scaled = int(y * scale_factor) cv2.putText(marked_image, f"Defect", (x_scaled, y_scaled), cv2.FONT_HERSHEY_SIMPLEX, 0.5 * scale_factor, (0, 255, 255), int(scale_factor)) return is_qualified, diff_ratio, marked_image # ==================== 视觉触发的质量检测流程 ==================== def vision_controlled_check(capture_image=None, match_score=0.0): """修改为接受图像帧和匹配分数""" global current_sample_path, detection_history logging.info("视觉触发质量检测启动") # 如果没有提供图像,使用当前帧 if capture_image is None: frame = obj_cam_operation.get_current_frame() else: frame = capture_image if frame is None: QMessageBox.warning(mainWindow, "错误", "无法获取当前帧图像!", QMessageBox.Ok) return progress = QProgressDialog("正在检测...", "取消", 0, 100, mainWindow) progress.setWindowModality(Qt.WindowModal) progress.setValue(10) try: diff_threshold = mainWindow.sliderDiffThreshold.value() / 100.0 logging.info(f"使用差异度阈值: {diff_threshold}") progress.setValue(30) is_qualified, diff_ratio, marked_image = enhanced_check_print_quality( current_sample_path, frame, threshold=diff_threshold ) progress.setValue(70) if is_qualified is None: QMessageBox.critical(mainWindow, "检测错误", "检测失败,请极光日志", QMessageBox.Ok) return logging.info(f"检测结果: 合格={is_qualified}, 差异={diff_ratio}") progress.setValue(90) update_diff_display(diff_ratio, is_qualified) result_text = f"印花是否合格: {'合格' if is_qualified else '不合格'}\n差异占比: {diff_ratio*100:.2f}%\n阈值: {diff_threshold*100:.2f}%" QMessageBox.information(mainWindow, "检测结果", result_text, QMessageBox.Ok) if marked_image is not None: # 创建可调整大小的窗口 cv2.namedWindow("缺陷标记结果", cv2.WINDOW_NORMAL) cv2.resizeWindow("缺陷标记结果", 800, 600) # 初始大小 cv2.imshow("缺陷标记结果", marked_image) cv2.waitKey(0) cv2.destroyAllWindows() detection_result = { 'timestamp': datetime.now(), 'qualified': is_qualified, 'diff_ratio': diff_ratio, 'threshold': diff_threshold, 'trigger_type': 'vision' if capture_image else 'manual' } detection_history.append(detection_result) update_history_display() progress.setValue(100) except Exception as e: logging.exception("印花检测失败") QMessageBox.critical(mainWindow, "检测错误", f"检测过程中发生错误: {str(e)}", QMessageBox.Ok) finally: progress.close() # ==================== 相机操作函数 ==================== def open_device(): global deviceList, nSelCamIndex, obj_cam_operation, isOpen, frame_monitor_thread, mainWindow if isOpen: QMessageBox.warning(mainWindow, "Error", '相机已打开!', QMessageBox.Ok) return MV_E_CALLORDER nSelCamIndex = mainWindow.ComboDevices.currentIndex() if nSelCamIndex < 0: QMessageBox.warning(mainWindow, "Error", '请选择相机!', QMessageBox.Ok) return MV_E_CALLORDER # 创建相机控制对象 cam = MvCamera() # 初始化相机操作对象 obj_cam_operation = CameraOperation(cam, deviceList, nSelCamIndex) ret = obj_cam_operation.open_device() if 0 != ret: strError = "打开设备失败 ret:" + ToHexStr(ret) QMessageBox.warning(mainWindow, "Error", strError, QMessageBox.Ok) isOpen = False else: set_continue_mode() get_param() isOpen = True enable_controls() # 创建并启动帧监控线程 frame_monitor_thread = FrameMonitorThread(obj_cam_operation) frame_monitor_thread.frame_status.connect(mainWindow.statusBar().showMessage) frame_monitor_thread.start() def start_grabbing(): global obj_cam_operation, isGrabbing, template_matcher_thread ret = obj_cam_operation.start_grabbing(mainWindow.widgetDisplay.winId()) if ret != 0: strError = "开始取流失败 ret:" + ToHexStr(ret) QMessageBox.warning(mainWindow, "Error", strError, QMessageBox.Ok) else: isGrabbing = True enable_controls() # 等待第一帧到达 QThread.msleep(500) if not obj_cam_operation.is_frame_available(): QMessageBox.warning(mainWindow, "警告", "开始取流后未接收到帧,请检查相机连接!", QMessageBox.Ok) # 如果启用了自动检测,启动检测线程 if mainWindow.chkContinuousMatch.isChecked(): toggle_template_matching(True) def stop_grabbing(): global obj_cam_operation, isGrabbing, template_matcher_thread ret = obj_cam_operation.Stop_grabbing() if ret != 0: strError = "停止取流失败 ret:" + ToHexStr(ret) QMessageBox.warning(mainWindow, "Error", strError, QMessageBox.Ok) else: isGrabbing = False enable_controls() # 停止模板匹配线程 if template_matcher_thread and template_matcher_thread.isRunning(): template_matcher_thread.stop() def close_device(): global isOpen, isGrabbing, obj_cam_operation, frame_monitor_thread, template_matcher_thread if frame_monitor_thread and frame_monitor_thread.isRunning(): frame_monitor_thread.stop() frame_monitor_thread.wait(2000) # 停止模板匹配线程 if template_matcher_thread and template_matcher_thread.isRunning(): template_matcher_thread.stop() template_matcher_thread.wait(2000) template_matcher_thread = None if isOpen and obj_cam_operation: obj_cam_operation.close_device() isOpen = False isGrabbing = False enable_controls() # ==================== 连续帧匹配检测器 ==================== class ContinuousFrameMatcher(QThread): frame_processed = pyqtSignal(np.ndarray, float, bool) # 处理后的帧, 匹配分数, 是否匹配 match_score_updated = pyqtSignal(float) # 匹配分数更新信号 match_success = pyqtSignal(np.ndarray, float) # 匹配成功信号 (帧, 匹配分数) trigger_activated = pyqtSignal(bool) # 新增信号:触发状态变化 def __init__(self, cam_operation, parent=None): super().__init__(parent) self.cam_operation = cam_operation self.running = True self.sample_template = None self.min_match_count = MIN_MATCH_COUNT self.match_threshold = MATCH_THRESHOLD self.sample_kp = None self.sample_des = None self.current_match_score = 0.0 self.last_match_time = 0 self.frame_counter = 0 self.consecutive_fail_count = 0 self.last_trigger_time = 0 # 上次触发时间 self.cool_down = 0.2 # 冷却时间(秒) self.trigger_threshold = 0.5 # 默认触发阈值 # 特征检测器 - 使用SIFT self.sift = cv2.SIFT_create() # 特征匹配器 - 使用FLANN提高匹配精度 FLANN_INDEX_KDTREE = 1 index_params = dict(algorithm=FLANN_INDEX_KDTREE, trees=5) search_params = dict(checks=50) self.flann = cv2.FlannBasedMatcher(index_params, search_params) # 性能监控 self.processing_times = deque(maxlen=100) self.frame_rates = deque(maxlen=100) # 黑白相机优化 self.clahe = cv2.createCLAHE(clipLimit=3.0, tileGridSize=(8, 8)) def calculate_match_score(self, good_matches): """更合理的匹配分数计算方法""" if not good_matches: return 0.0 # 计算平均匹配质量(距离的倒数) total_quality = 0.0 for match in good_matches: # 距离越小匹配越好,但避免除以0 if match.distance < 1e-5: total_quality += 1.0 else: total_quality += 1.0 / match.distance # 使用特征点数量和平均质量计算分数 avg_quality = total_quality / len(good_matches) match_score = min(1.0, max(0.0, avg_quality * 0.5)) # 调整比例因子 return match_score def preprocess_image(self, image): """增强黑白图像特征提取""" # 如果是单通道图像,转换为三通道 if len(image.shape) == 2: image = cv2.cvtColor(image, cv2.COLOR_GRAY2BGR) # 对比度增强 (LAB空间) lab = cv2.cvtColor(image, cv2.COLOR_BGR2LAB) l, a, b = cv2.split(lab) cl = self.clahe.apply(l) limg = cv2.merge((cl, a, b)) enhanced = cv2.cvtColor(limg, cv2.COLOR_LAB2BGR) # 边缘增强 gray = cv2.cvtColor(enhanced, cv2.COLOR_BGR2GRAY) edges = cv2.Canny(gray, 50, 150) # 组合特征 return cv2.addWeighted(enhanced, 0.7, cv2.cvtColor(edges, cv2.COLOR_GRAY2BGR), 0.3, 0) def set_sample(self, sample_img): """设置标准样本并提取特征""" # 保存样本图像 self.sample_img = sample_img # 预处理增强特征 processed_sample = self.preprocess_image(sample_img) # 提取样本特征点 self.sample_kp, self.sample_des = self.sift.detectAndCompute(processed_sample, None) if self.sample_des is None or len(self.sample_kp) < 100: # 增加最小特征点要求 logging.warning(f"样本特征点不足({len(self.sample_kp)}个),需要至少100个") return False logging.info(f"样本特征提取成功: {len(self.sample_kp)}个关键点") return True def set_threshold(self, threshold): """更新匹配阈值""" self.match_threshold = max(0.0, min(1.0, threshold)) logging.info(f"更新匹配阈值: {self.match_threshold:.2f}") def set_trigger_threshold(self, threshold): """更新触发阈值""" self.trigger_threshold = max(0.0, min(1.0, threshold)) logging.info(f"更新触发阈值: {self.trigger_threshold:.2f}") def process_frame(self, frame): """处理帧:特征提取、匹配和可视化""" is_matched = False match_score = 0.0 processed_frame = frame.copy() # 检查是否已设置样本 if self.sample_kp is None or self.sample_des is None: return processed_frame, match_score, is_matched # 预处理当前帧 processed_frame = self.preprocess_image(frame) # 转换为灰度图像用于特征提取 gray_frame = cv2.cvtColor(processed_frame, cv2.COLOR_BGR2GRAY) try: # 提取当前帧的特征点 kp, des = self.sift.detectAndCompute(gray_frame, None) if des is None or len(kp) < 5: # 特征点不足 return processed_frame, match_score, is_matched # 匹配特征点 matches = self.flann.knnMatch(self.sample_des, des, k=2) # 应用Lowe's比率测试 good_matches = [] for m, n in matches: if m.distance < 0.7 * n.distance: good_matches.append(m) # 使用更科学的匹配分数计算方法 match_score = self.calculate_match_score(good_matches) # 判断是否匹配成功(用于UI显示) if len(good_matches) >= self.min_match_count and match_score >= self.match_threshold: is_matched = True # 在图像上绘制匹配结果 if len(gray_frame.shape) == 2: processed_frame = cv2.cvtColor(gray_frame, cv2.COLOR_GRAY2BGR) # 绘制匹配点 processed_frame = cv2.drawMatches( self.sample_img, self.s极光, processed_frame, kp, good_matches, None, flags=cv2.DrawMatchesFlags_NOT_DRAW_SINGLE_POINTS ) # 在图像上显示匹配分数 cv2.putText(processed_frame, f"Match Score: {match_score:.2f}", (20, 30), cv2.FONT_HERSHEY_SIMPLEX, 0.8, (0, 255, 0), 2) # 更新当前匹配分数 self.current_match_score = match_score self.match_score_updated.emit(match_score) # 检查是否达到触发条件(50%以上)并且超过冷却时间 trigger_active = False current_time = time.time() if match_score >= self.trigger_threshold and (current_time - self.last_trigger_time) > self.cool_down: self.last_trigger_time = current_time trigger_active = True logging.info(f"匹配分数达到触发阈值! 分数: {match_score:.2f}, 触发质量检测") # 发出匹配成功信号 (传递当前帧) self.match_success.emit(frame.copy(), match_score) # 发送触发状态信号 self.trigger_activated.emit(trigger_active) except Exception as e: logging.error(f"帧处理错误: {str(e)}") return processed_frame, match_score, is_matched def run(self): """主处理循环 - 连续处理每一帧""" logging.info("连续帧匹配线程启动") self.last_match_time = time.time() self.consecutive_fail_count = 0 while self.running: start_time = time.time() # 检查相机状态 if not self.cam_operation or not self.cam_operation.is_grabbing: if self.consecutive_fail_count % 10 == 0: logging.debug("相机未取流,等待...") time.sleep(0.1) self.consecutive_fail_count += 1 continue # 获取当前帧 frame = self.cam_operation.get_current_frame() if frame is None: self.consecutive_fail_count += 1 if self.consecutive_fail_count % 10 == 0: logging.warning(f"连续{self.consecutive_fail_count}次获取帧失败") time.sleep(0.05) continue self.consecutive_fail_count = 0 try: # 处理帧 processed_frame, match_score, is_matched = self.process_frame(frame) # 发送处理结果 self.frame_processed.emit(processed_frame, match_score, is_matched) except Exception as e: logging.error(f"帧处理错误: {str(e)}") # 控制处理频率 processing_time = time.time() - start_time sleep_time = max(0.01, MIN_FRAME_INTERVAL - processing_time) time.sleep(sleep_time) logging.info("连续帧匹配线程退出") # ==================== 模板匹配控制函数 ==================== def toggle_template_matching(state): global template_matcher_thread, current_sample_path logging.debug(f"切换连续匹配状态: {state}") if state == Qt.Checked and isGrabbing: # 确保已设置样本 if not current_sample_path: logging.warning("尝试启动连续匹配但未设置样本") QMessageBox.warning(mainWindow, "错误", "请先设置标准样本", QMessageBox.Ok) mainWindow.chkContinuousMatch.setChecked(False) return if template_matcher_thread is None: logging.info("创建新的连续帧匹配线程") template_matcher_thread = ContinuousFrameMatcher(obj_cam_operation) template_matcher_thread.frame_processed.connect(update_frame_display) template_matcher_thread.match_score_updated.connect(update_match_score_display) template_matcher_thread.trigger_activated.connect( lambda active: mainWindow.update_trigger_indicator(active) ) # 正确连接匹配成功信号到质量检测函数 template_matcher_thread.match_success.connect( lambda frame, score: vision_controlled_check(frame, score) ) # 加载样本图像 sample_img = cv2.imread(current_sample_path) if sample_img is None: logging.error("无法加载标准样本图像") QMessageBox.warning(mainWindow, "错误", "无法加载标准样本图像", QMessageBox.Ok) mainWindow.chkContinuousMatch.setChecked(False) return if not template_matcher_thread.set_sample(sample_img): logging.warning("标准样本特征不足") QMessageBox.warning(mainWindow, "错误", "标准样本特征不足", QMessageBox.Ok) mainWindow.chkContinuousMatch.setChecked(False) return if not template_matcher_thread.isRunning(): logging.info("启动连续帧匹配线程") template_matcher_thread.start() elif template_matcher_thread and template_matcher_thread.isRunning(): logging.info("停止连续帧匹配线程") template_matcher_thread.stop() # 重置匹配分数显示 update_match_score_display(0.0) # 重置帧显示 if obj_cam_operation and obj_cam_operation.is_frame_available(): frame = obj_cam_operation.get_current_frame() if frame is not None: display_frame = frame.copy() # 添加状态信息 cv2.putText(display_frame, "Continuous Matching Disabled", (20, 30), cv2.FONT_HERSHEY_SIMPLEX, 0.8, (0, 0, 255), 2) update_frame_display(display_frame, 0.0, False) # 添加类型转换函数 def numpy_to_qimage(np_array): """将 numpy 数组转换为 QImage""" if np_array is None: return QImage() height, width, channel = np_array.shape bytes_per_line = 3 * width # 确保数据是连续的 if not np_array.flags['C_CONTIGUOUS']: np_array = np.ascontiguousarray(np_array) # 转换 BGR 到 RGB rgb_image = cv2.cvtColor(np_array, cv2.COLOR_BGR2RGB) # 创建 QImage qimg = QImage( rgb_image.data, width, height, bytes_per_line, QImage.Format_RGB888 ) # 复制数据以避免内存问题 return qimg.copy() # 修改 update_frame_display 函数 def update_frame_display(frame, match_score, is_matched): """更新主显示窗口(线程安全)""" # 确保在GUI线程中执行 if QThread.currentThread() != QApplication.instance().thread(): # 转换为 QImage 再传递 qimg = numpy_to_qimage(frame) QMetaObject.invokeMethod( mainWindow, "updateDisplay", Qt.QueuedConnection, Q_ARG(QImage, qimg), Q_ARG(float, match_score), Q_ARG(bool, is_matched) ) return # 如果已经在主线程,直接调用主窗口的更新方法 mainWindow.updateDisplay(frame, match_score, is_matched) def update_match_score_display(score): """更新匹配分数显示""" # 将分数转换为百分比显示 score_percent = score * 100 mainWindow.lblMatchScoreValue.setText(f"{score_percent:.1f}%") # 根据分数设置颜色 if score > 0.8: # 高于80%显示绿色 color = "green" elif score > 0.6: # 60%-80%显示黄色 color = "orange" else: # 低于60%显示红色 color = "red" mainWindow.lblMatchScoreValue.setStyleSheet(f"color: {color}; font-weight: bold;") def update_diff_display(diff_ratio, is_qualified): mainWindow.lblCurrentDiff.setText(f"当前差异度: {diff_ratio*100:.2f}%") if is_qualified: mainWindow.lblDiffStatus.setText("状态: 合格") mainWindow.lblDiffStatus.setStyleSheet("color: green; font-size: 12px;") else: mainWindow.lblDiffStatus.setText("状态: 不合格") mainWindow.lblDiffStatus.setStyleSheet("color: red; font-size: 12px;") def update_diff_threshold(value): mainWindow.lblDiffValue.setText(f"{value}%") def update_sample_display(): global current_sample_path if current_sample_path: mainWindow.lblSamplePath.setText(f"当前样本: {os.path.basename(current_sample_path)}") mainWindow.lblSamplePath.setToolTip(current_sample_path) mainWindow.bnPreviewSample.setEnabled(True) else: mainWindow.lblSamplePath.setText("当前样本: 未设置样本") mainWindow.bnPreviewSample.setEnabled(False) def update_history_display(): global detection_history mainWindow.cbHistory.clear() for i, result in enumerate(detection_history[-10:]): timestamp = result['timestamp'].strftime("%H:%M:%S") status = "合格" if result['qualified'] else "不合格" ratio = f"{result['diff_ratio']*100:.2f}%" trigger = "视觉" if result['trigger_type'] == 'vision' else "手动" mainWindow.cbHistory.addItem(f"[{trigger} {timestamp}] {status} - 差异: {ratio}") def update_match_threshold(value): """更新匹配阈值显示并应用到匹配器""" global template_matcher_thread # 更新UI显示 if mainWindow: mainWindow.lblThresholdValue.setText(f"{value}%") # 如果匹配线程存在,更新其匹配阈值 if template_matcher_thread: # 转换为0-1范围的浮点数 threshold = value / 100.0 template_matcher_thread.set_threshold(threshold) logging.debug(f"更新匹配阈值: {threshold:.2f}") # 新增函数:保存当前帧 def save_current_frame(): if not isGrabbing: QMessageBox.warning(mainWindow, "错误", "请先开始取流并捕获图像!", QMessageBox.Ok) return frame = obj_cam_operation.get_current_frame() if frame is None: QMessageBox.warning(mainWindow, "无有效图像", "未捕获到有效图像,请检查相机状态!", QMessageBox.Ok) return settings = QSettings("ClothInspection", "CameraApp") last_dir = settings.value("last_save_dir", os.path.join(os.getcwd(), "captures")) timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") default_filename = f"capture_{timestamp}" file_path, selected_filter = QFileDialog.getSaveFileName( mainWindow, "保存当前帧", os.path.join(last_dir, default_filename), "PNG Files (*.png);;BMP Files (*.bmp);;JPEG Files (*.jpg);;所有文件 (*)", options=QFileDialog.DontUseNativeDialog ) if not file_path: return # 确保文件扩展名正确 if not os.path.splitext(file_path)[1]: if "PNG" in selected_filter: file_path += ".png" elif "BMP" in selected_filter: file_path += ".bmp" elif "JPEG" in selected_filter or "JPG" in selected_filter: file_path += ".jpg" # 保存图像 try: if cv2.imwrite(file_path, frame): QMessageBox.information(mainWindow, "成功", f"当前帧已保存至:\n{file_path}", QMessageBox.Ok) else: raise Exception("OpenCV保存失败") except Exception as e: QMessageBox.critical(mainWindow, "保存错误", f"保存图像时发生错误:\n{str(e)}", QMessageBox.Ok) # ==================== 主窗口类 ==================== class MainWindow(QMainWindow): def __init__(self): super().__init__() self.setWindowTitle("布料印花检测系统 - 连续匹配版") self.resize(1200, 800) central_widget = QWidget() self.setCentralWidget(central_widget) main_layout = QVBoxLayout(central_widget) # 设备枚举区域 device_layout = QHBoxLayout() self.ComboDevices = QComboBox() self.bnEnum = QPushButton("枚举设备") self.bnOpen = QPushButton("打开设备") self.bnClose = QPushButton("关闭设备") device_layout.addWidget(self.ComboDevices) device_layout.addWidget(self.bnEnum) device_layout.addWidget(self.bnOpen) device_layout.addWidget(self.bnClose) main_layout.addLayout(device_layout) # 取流控制组 self.groupGrab = QGroupBox("取流控制") grab_layout = QHBoxLayout(self.groupGrab) self.bnStart = QPushButton("开始取流") self.bnStop = QPushButton("停止取流") self.radioContinueMode = QRadioButton("连续模式") self.radioTriggerMode = QRadioButton("触发模式") self.bnSoftwareTrigger = QPushButton("软触发") grab_layout.addWidget(self.bnStart) grab_layout.addWidget(self.bnStop) grab_layout.addWidget(self.radioContinueMode) grab_layout.addWidget(self.radioTriggerMode) grab_layout.addWidget(self.bnSoftwareTrigger) main_layout.addWidget(self.groupGrab) # 参数设置组 self.paramgroup = QGroupBox("相机参数") param_layout = QGridLayout(self.paramgroup) self.edtExposureTime = QLineEdit() self.edtGain = QLineEdit() self.edtFrameRate = QLineEdit() self.bnGetParam = QPushButton("获取参数") self.bnSetParam = QPushButton("设置参数") self.bnSaveImage = QPushButton("保存图像") param_layout.addWidget(QLabel("曝光时间:"), 0, 0) param_layout.addWidget(self.edtExposureTime, 0, 1) param_layout.addWidget(self.bnGetParam, 0, 2) param_layout.addWidget(QLabel("增益:"), 1, 0) param_layout.addWidget(self.edtGain, 1, 1) param_layout.addWidget(self.bnSetParam, 1, 2) param_layout.addWidget(QLabel("帧率:"), 2, 0) param_layout.addWidget(self.edtFrameRate, 2, 1) param_layout.addWidget(self.bnSaveImage, 2, 2) main_layout.addWidget(self.paramgroup) # 图像显示区域 self.widgetDisplay = QLabel() self.widgetDisplay.setMinimumSize(640, 480) self.widgetDisplay.setStyleSheet("background-color: black;") self.widgetDisplay.setAlignment(Qt.AlignCenter) self.widgetDisplay.setText("相机预览区域") main_layout.addWidget(self.widgetDisplay, 1) # 创建自定义UI组件 self.setup_custom_ui() # 添加阈值自适应定时器 self.threshold_timer = QTimer() self.threshold_timer.timeout.connect(self.auto_adjust_threshold) self.threshold_timer.start(2000) # 每2秒调整一次 def auto_adjust_threshold(self): """根据环境亮度自动调整匹配阈值""" if not obj_cam_operation or not isGrabbing: return # 获取当前帧 frame = obj_cam_operation.get_current_frame() if frame is None: return # 处理不同通道数的图像 if len(frame.shape) == 2 or frame.shape[2] == 1: # 已经是灰度图 gray = frame elif frame.shape[2] == 3: # 三通道彩色图 gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) elif frame.shape[2] == 4: # 四通道图(带alpha) gray = cv2.cvtColor(frame, cv2.COLOR_BGRA2GRAY) else: # 其他通道数,无法处理 logging.warning(f"无法处理的图像格式: {frame.shape}") return # 计算平均亮度 try: brightness = np.mean(gray) except Exception as e: logging.error(f"计算亮度失败: {str(e)}") return # 根据亮度动态调整阈值 (亮度低时降低阈值要求) if brightness < 50: # 暗环境 new_threshold = 40 # 40% elif brightness > 200: # 亮环境 new_threshold = 65 # 65% else: # 正常环境 new_threshold = 55 # 55% # 更新UI self.sliderThreshold.setValue(new_threshold) self.lblThresholdValue.setText(f"{new_threshold}%") # 更新匹配器阈值 update_match_threshold(new_threshold) # 状态栏显示调整信息 self.statusBar().showMessage(f"亮度: {brightness:.1f}, 自动调整阈值至: {new_threshold}%", 3000) def update_trigger_indicator(self, active): """更新触发指示灯状态""" if active: self.triggerIndicator.setStyleSheet("background-color: green; border-radius: 10px;") else: self.triggerIndicator.setStyleSheet("background-color: gray; border-radius: 10px;") def update_trigger_threshold(self, value): """更新触发阈值显示并应用到匹配器""" self.lblTriggerValue.setText(f"{value}%") threshold = value / 100.0 if template_matcher_thread: template_matcher_thread.set_trigger_threshold(threshold) def setup_custom_ui(self): # 工具栏 toolbar = self.addToolBar("检测工具") self.bnCheckPrint = QPushButton("手动检测") toolbar.addWidget(self.bnCheckPrint) # 添加分隔标签 toolbar.addWidget(QLabel("图像保存:")) self.bnSaveCurrentFrame = QPushButton("保存当前帧") toolbar.addWidget(self.bnSaveCurrentFrame) self.bnSaveSample = QPushButton("保存标准样本") toolbar.addWidget(self.bnSaveSample) self.bnPreviewSample = QPushButton("预览样本") toolbar.addWidget(self.bnPreviewSample) # 添加触发指示灯 self.triggerIndicator = QLabel() self.triggerIndicator.setFixedSize(20, 20) self.triggerIndicator.setStyleSheet("background-color: gray; border-radius: 10px;") toolbar.addWidget(QLabel("触发状态:")) toolbar.addWidget(self.triggerIndicator) # 历史记录 toolbar.addWidget(QLabel("历史记录:")) self.cbHistory = QComboBox() self.cbHistory.setMinimumWidth(300) toolbar.addWidget(self.cbHistory) # 状态栏样本路径 self.lblSamplePath = QLabel("当前样本: 未设置样本") self.statusBar().addPermanentWidget(self.lblSamplePath) # 右侧面板 right_panel = QWidget() right_layout = QVBoxLayout(right_panel) right_layout.setContentsMargins(10, 10, 10, 10) # 差异度调整组 diff_group = QGroupBox("差异度调整") diff_layout = QVBoxLayout(diff_group) self.lblDiffThreshold = QLabel("差异度阈值 (0-100%):") self.sliderDiffThreshold = QSlider(Qt.Horizontal) self.sliderDiffThreshold.setRange(0, 100) self.sliderDiffThreshold.setValue(5) self.lblDiffValue = QLabel("5%") self.lblCurrentDiff = QLabel("当前差异度: -") self.lblCurrentDiff.setStyleSheet("font-size: 14px; font-weight: bold;") self.lblDiffStatus = QLabel("状态: 未检测") self.lblDiffStatus.setStyleSheet("font-size: 12px;") diff_layout.addWidget(self.lblDiffThreshold) diff_layout.addWidget(self.sliderDiffThreshold) diff_layout.addWidget(self.lblDiffValue) diff_layout.addWidget(self.lblCurrentDiff) diff_layout.addWidget(self.lblDiffStatus) right_layout.addWidget(diff_group) # ===== 连续匹配面板 ===== match_group = QGroupBox("连续帧匹配") match_layout = QVBoxLayout(match_group) # 样本设置 sample_layout = QHBoxLayout() self.bnSetSample = QPushButton("设置标准样本") self.bnPreviewSample = QPushButton("预览样本") self.lblSampleStatus = QLabel("状态: 未设置样本") sample_layout.addWidget(self.bnSetSample) sample_layout.addWidget(self.bnPreviewSample) sample_layout.addWidget(self.lblSampleStatus) match_layout.addLayout(sample_layout) # 匹配参数 param_layout = QHBoxLayout() self.lblMatchThreshold = QLabel("匹配阈值:") self.sliderThreshold = QSlider(Qt.Horizontal) self.sliderThreshold.setRange(50, 100) self.sliderThreshold.setValue(75) # 降低默认阈值 self.lblThresholdValue = QLabel("75%") param_layout.addWidget(self.lblMatchThreshold) param_layout.addWidget(self.sliderThreshold) param_layout.addWidget(self.lblThresholdValue) match_layout.addLayout(param_layout) # 触发阈值调整 trigger_threshold_layout = QHBoxLayout() self.lblTriggerThreshold = QLabel("触发阈值(%):") self.sliderTriggerThreshold = QSlider(Qt.Horizontal) self.sliderTriggerThreshold.setRange(0, 100) self.sliderTriggerThreshold.setValue(50) # 默认50% self.lblTriggerValue = QLabel("50%") trigger_threshold_layout.addWidget(self.lblTriggerThreshold) trigger_threshold_layout.addWidget(self.sliderTriggerThreshold) trigger_threshold_layout.addWidget(self.lblTriggerValue) match_layout.addLayout(trigger_threshold_layout) # 匹配分数显示 match_score_layout = QHBoxLayout() self.lblMatchScore = QLabel("实时匹配分数:") self.lblMatchScoreValue = QLabel("0.0%") self.lblMatchScoreValue.setStyleSheet("font-weight: bold;") match_score_layout.addWidget(self.lblMatchScore) match_score_layout.addWidget(self.lblMatchScoreValue) match_layout.addLayout(match_score_layout) # 连续匹配开关 self.chkContinuousMatch = QCheckBox("启用连续帧匹配") self.chkContinuousMatch.setChecked(False) match_layout.addWidget(self.chkContinuousMatch) right_layout.addWidget(match_group) right_layout.addStretch(1) # 停靠窗口 dock = QDockWidget("检测控制面板", self) dock.setWidget(right_panel) dock.setFeatures(QDockWidget.DockWidgetMovable | QDockWidget.DockWidgetFloatable) self.addDockWidget(Qt.RightDockWidgetArea, dock) @pyqtSlot(QImage, float, bool) def updateDisplay(self, qimg, match_score, is_matched): """线程安全的显示更新方法(只接收 QImage)""" if qimg.isNull(): return # 创建QPixmap并缩放 pixmap = QPixmap.fromImage(qimg) scaled_pixmap = pixmap.scaled( self.widgetDisplay.size(), Qt.KeepAspectRatio, Qt.SmoothTransformation ) # 更新显示 self.widgetDisplay.setPixmap(scaled_pixmap) self.widgetDisplay.setAlignment(Qt.AlignCenter) def closeEvent(self, event): logging.info("主窗口关闭,执行清理...") close_device() event.accept() # ===== 辅助函数 ===== def ToHexStr(num): if not isinstance(num, int): try: num = int(num) except: return f"<非整数:{type(num)}>" chaDic = {10: 'a', 11: 'b', 12: 'c', 13: 'd', 14: 'e', 15: 'f'} hexStr = "" if num < 0: num = num + 2 ** 32 while num >= 16: digit = num % 16 hexStr = chaDic.get(digit, str(digit)) + hexStr num //= 16 hexStr = chaDic.get(num, str(num)) + hexStr return "0x" + hexStr def enum_devices(): global deviceList, obj_cam_operation n_layer_type = ( MV_GIGE_DEVICE | MV_USB_DEVICE | MV_GENTL_CAMERALINK_DEVICE | MV_GENTL_CXP_DEVICE | MV_GENTL_XOF_DEVICE ) # 创建设备列表 deviceList = MV_CC_DEVICE_INFO_LIST() # 枚举设备 ret = MvCamera.MV_CC_EnumDevices(n_layer_type, deviceList) if ret != MV_OK: error_msg = f"枚举设备失败! 错误码: 0x{ret:x}" logging.error(error_msg) QMessageBox.warning(mainWindow, "错误", error_msg, QMessageBox.Ok) return ret if deviceList.nDeviceNum == 0: QMessageBox.warning(mainWindow, "提示", "未找到任何设备", QMessageBox.Ok) return MV_OK logging.info(f"找到 {deviceList.nDeviceNum} 个设备") # 处理设备信息 devList = [] for i in range(deviceList.nDeviceNum): # 获取设备信息 mvcc_dev_info = ctypes.cast( deviceList.pDeviceInfo[i], ctypes.POINTER(MV_CC_DEVICE_INFO) ).contents # 根据设备类型提取信息 if mvcc_dev_info.nTLayerType == MV_GIGE_DEVICE: st_gige_info = mvcc_dev_info.SpecialInfo.stGigEInfo ip_addr = ( f"{(st_gige_info.nCurrentIp >> 24) & 0xFF}." f"{(st_gige_info.nCurrentIp >> 16) & 0xFF}." f"{(st_gige_info.nCurrentIp >> 8) & 0xFF}." f"{st_gige_info.nCurrentIp & 0xFF}" ) # 修复:将c_ubyte_Array_16转换为字节串再解码 user_defined_bytes = bytes(st_gige_info.chUserDefinedName) dev_name = f"GigE: {user_defined_bytes.decode('gbk', 'ignore')}" devList.append(f"[{i}] {dev_name} ({ip_addr})") elif mvcc_dev_info.nTLayerType == MV_USB_DEVICE: st_usb_info = mvcc_dev_info.SpecialInfo.stUsb3VInfo serial = bytes(st_usb_info.chSerialNumber).decode('ascii', 'ignore').rstrip('\x00') # 修复:同样处理用户自定义名称 user_defined_bytes = bytes(st_usb_info.chUserDefinedName) dev_name = f"USB: {user_defined_bytes.decode('gbk', 'ignore')}" devList.append(f"[{i}] {dev_name} (SN: {serial})") else: devList.append(f"[{i}] 未知设备类型: {mvcc_dev_info.nTLayerType}") # 更新UI mainWindow.ComboDevices.clear() mainWindow.ComboDevices.addItems(devList) if devList: mainWindow.ComboDevices.setCurrentIndex(0) mainWindow.statusBar().showMessage(f"找到 {deviceList.nDeviceNum} 个设备", 300) return MV_OK def set_continue_mode(): ret = obj_cam_operation.set_trigger_mode(False) if ret != 0: strError = "设置连续模式失败 ret:" + ToHexStr(ret) QMessageBox.warning(mainWindow, "Error", strError, QMessageBox.Ok) else: mainWindow.radioContinueMode.setChecked(True) mainWindow.radioTriggerMode.setChecked(False) mainWindow.bnSoftwareTrigger.setEnabled(False) def set_software_trigger_mode(): ret = obj_cam_operation.set_trigger_mode(True) if ret != 0: strError = "设置触发模式失败 ret:" + ToHexStr(ret) QMessageBox.warning(mainWindow, "Error", strError, QMessageBox.Ok) else: mainWindow.radioContinueMode.setChecked(False) mainWindow.radioTriggerMode.setChecked(True) mainWindow.bnSoftwareTrigger.setEnabled(isGrabbing) def trigger_once(): ret = obj_cam_operation.trigger_once() if ret != 0: strError = "软触发失败 ret:" + ToHexStr(ret) QMessageBox.warning(mainWindow, "Error", strError, QMessageBox.Ok) def save_sample_image(): global isGrabbing, obj_cam_operation, current_sample_path if not isGrabbing: QMessageBox.warning(mainWindow, "错误", "请先开始取流并捕获图像!", QMessageBox.Ok) return # 尝试捕获当前帧 frame = obj_cam_operation.capture_frame() if frame is None: QMessageBox.warning(mainWindow, "无有效图像", "未捕获到有效图像,请检查相机状态!", QMessageBox.Ok) return # 确保图像有效 if frame.size == 0 or frame.shape[0] == 0 or frame.shape[1] == 0: QMessageBox.warning(mainWindow, "无效图像", "捕获的图像无效,请检查相机设置!", QMessageBox.Ok) return settings = QSettings("ClothInspection", "CameraApp") last_dir = settings.value("last_save_dir", os.path.join(os.getcwd(), "captures")) timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") default_filename = f"sample_{timestamp}" file_path, selected_filter = QFileDialog.getSaveFileName( mainWindow, "保存标准样本图像", os.path.join(last_dir, default_filename), "BMP Files (*.bmp);;PNG Files (*.png);;JPEG Files (*.jpg);;所有文件 (*)", options=QFileDialog.DontUseNativeDialog ) if not file_path: return # 确保文件扩展名正确 file_extension = os.path.splitext(file_path)[1].lower() if not file_extension: if "BMP" in selected_filter: file_path += ".bmp" elif "PNG" in selected_filter: file_path += ".png" elif "JPEG" in selected_filter or "JPG" in selected_filter: file_path += ".jpg" else: file_path += ".bmp" file_extension = os.path.splitext(file_path)[1].lower() # 创建目录(如果不存在) directory = os.path.dirname(file_path) if directory and not os.path.exists(directory): try: os.makedirs(directory, exist_ok=True) except OSError as e: QMessageBox.critical(mainWindow, "目录创建错误", f"无法创建目录 {directory}: {str(e)}", QMessageBox.Ok) return # 保存图像 try: # 使用OpenCV保存图像 if not cv2.imwrite(file_path, frame): raise Exception("OpenCV保存失败") # 更新状态 current_sample_path = file_path update_sample_display() settings.setValue("last_save_dir", os.path.dirname(file_path)) # 显示成功消息 QMessageBox.information(mainWindow, "成功", f"标准样本已保存至:\n{file_path}", QMessageBox.Ok) # 更新样本状态 mainWindow.lblSampleStatus.setText("状态: 样本已设置") mainWindow.lblSampleStatus.setStyleSheet("color: green;") except Exception as e: logging.error(f"保存图像失败: {str(e)}") QMessageBox.critical(mainWindow, "保存错误", f"保存图像时发生错误:\n{str(e)}", QMessageBox.Ok) def preview_sample(): global current_sample_path if not current_sample_path or not os.path.exists(current_sample_path): QMessageBox.warning(mainWindow, "错误", "请先设置有效的标准样本图像!", QMessageBox.Ok) return try: # 直接使用OpenCV加载图像 sample_img = cv2.imread(current_sample_path) if sample_img is None: raise Exception("无法加载图像") # 显示图像 cv2.namedWindow("标准样本预览", cv2.WINDOW_NORMAL) cv2.resizeWindow("标准样本预览", 800, 600) cv2.imshow("标准样本预览", sample_img) cv2.waitKey(0) cv2.destroyAllWindows() except Exception as e: QMessageBox.warning(mainWindow, "错误", f"预览样本失败: {str(e)}", QMessageBox.Ok) def is_float(str): try: float(str) return True except ValueError: return False def get_param(): try: ret = obj_cam_operation.get_parameters() if ret != MV_OK: strError = "获取参数失败,错误码: " + ToHexStr(ret) QMessageBox.warning(mainWindow, "错误", strError, QMessageBox.Ok) else: mainWindow.edtExposureTime.setText("{0:.2f}".format(obj_cam_operation.exposure_time)) mainWindow.edtGain.setText("{0:.2f}".format(obj_cam_operation.gain)) mainWindow.edtFrameRate.setText("{0:.2f}".format(obj_cam_operation.frame_rate)) except Exception as e: error_msg = f"获取参数时发生错误: {str(e)}" QMessageBox.critical(mainWindow, "严重错误", error_msg, QMessageBox.Ok) def set_param(): frame_rate = mainWindow.edtFrameRate.text() exposure = mainWindow.edtExposureTime.text() gain = mainWindow.edtGain.text() if not (is_float(frame_rate) and is_float(exposure) and is_float(gain)): strError = "设置参数失败: 参数必须是有效的浮点数" QMessageBox.warning(mainWindow, "错误", strError, QMessageBox.Ok) return MV_E_PARAMETER try: ret = obj_cam_operation.set_param( frame_rate=float(frame_rate), exposure_time=float(exposure), gain=float(gain) ) if ret != MV_OK: strError = "设置参数失败,错误码: " + ToHexStr(ret) QMessageBox.warning(mainWindow, "错误", strError, QMessageBox.Ok) except Exception as e: error_msg = f"设置参数时发生错误: {str(e)}" QMessageBox.critical(mainWindow, "严重错误", error_msg, QMessageBox.Ok) def enable_controls(): global isGrabbing, isOpen mainWindow.groupGrab.setEnabled(isOpen) mainWindow.paramgroup.setEnabled(isOpen) mainWindow.bnOpen.setEnabled(not isOpen) mainWindow.bnClose.setEnabled(isOpen) mainWindow.bnStart.setEnabled(isOpen and (not isGrabbing)) mainWindow.bnStop.setEnabled(isOpen and isGrabbing) mainWindow.bnSoftwareTrigger.setEnabled(isGrabbing and mainWindow.radioTriggerMode.isChecked()) mainWindow.bnSaveImage.setEnabled(isOpen and isGrabbing) mainWindow.bnCheckPrint.setEnabled(isOpen and isGrabbing) mainWindow.bnSaveSample.setEnabled(isOpen and isGrabbing) mainWindow.bnPreviewSample.setEnabled(bool(current_sample_path)) mainWindow.bnSaveCurrentFrame.setEnabled(isOpen and isGrabbing) # 连续匹配控制 mainWindow.chkContinuousMatch.setEnabled(bool(current_sample_path) and isGrabbing) # ===== 相机帧监控线程 ===== class FrameMonitorThread(QThread): frame_status = pyqtSignal(str) # 用于发送状态消息的信号 def __init__(self, cam_operation): super().__init__() self.cam_operation = cam_operation self.running = True self.frame_count = 0 self.last_time = time.time() def run(self): """监控相机帧状态的主循环""" while self.running: try: if self.cam_operation and self.cam_operation.is_grabbing: # 获取帧统计信息 frame_info = self.get_frame_info() if frame_info: fps = frame_info.get('fps', 0) dropped = frame_info.get('dropped', 0) status = f"FPS: {fps:.1f} | 丢帧: {dropped}" self.frame_status.emit(status) else: self.frame_status.emit("取流中...") else: self.frame_status.emit("相机未取流") except Exception as e: self.frame_status.emit(f"监控错误: {str(e)}") # 每500ms检查一次 QThread.msleep(500) def stop(self): """停止监控线程""" self.running = False self.wait(1000) # 等待线程结束 def calculate_fps(self): """计算当前帧率""" current_time = time.time() elapsed = current_time - self.last_time if elapsed > 0: fps = self.frame_count / elapsed self.frame_count = 0 self.last_time = current_time return fps return 0 def get_frame_info(self): """获取帧信息""" try: # 更新帧计数 self.frame_count += 1 # 返回帧信息 return { 'fps': self.calculate_fps(), 'dropped': 0 # 实际应用中需要从相机获取真实丢帧数 } except Exception as e: logging.error(f"获取帧信息失败: {str(e)}") return None # ===== 主程序入口 ===== if __name__ == "__main__": # 配置日志系统 logging.basicConfig( level=logging.DEBUG, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', handlers=[ logging.FileHandler("cloth_inspection_continuous.log"), logging.StreamHandler() ] ) logging.info("布料印花检测系统(连续匹配版)启动") app = QApplication(sys.argv) mainWindow = MainWindow() # 信号连接 mainWindow.sliderThreshold.valueChanged.connect(update_match_threshold) mainWindow.sliderTriggerThreshold.valueChanged.connect( mainWindow.update_trigger_threshold ) # 其他信号连接 mainWindow.sliderDiffThreshold.valueChanged.connect(update_diff_threshold) mainWindow.bnCheckPrint.clicked.connect(lambda: vision_controlled_check(None)) mainWindow.bnSaveSample.clicked.connect(save_sample_image) mainWindow.bnPreviewSample.clicked.connect(preview_sample) mainWindow.bnEnum.clicked.connect(enum_devices) mainWindow.bnOpen.clicked.connect(open_device) mainWindow.bnClose.clicked.connect(close_device) mainWindow.bnStart.clicked.connect(start_grabbing) mainWindow.bnStop.clicked.connect(stop_grabbing) mainWindow.bnSoftwareTrigger.clicked.connect(trigger_once) mainWindow.radioTriggerMode.clicked.connect(set_software_trigger_mode) mainWindow.radioContinueMode.clicked.connect(set_continue_mode) mainWindow.bnGetParam.clicked.connect(get_param) mainWindow.bnSetParam.clicked.connect(set_param) mainWindow.bnSaveImage.clicked.connect(save_current_frame) mainWindow.bnSaveCurrentFrame.clicked.connect(save_current_frame) # 连续匹配信号连接 mainWindow.sliderThreshold.valueChanged.connect(update_match_score_display) mainWindow.chkContinuousMatch.stateChanged.connect(toggle_template_matching) mainWindow.show() app.exec_() close_device() sys.exit()

class MainWindow(QMainWindow): def init(self, user_id): super().init() self.user_id = user_id self.initUI() # 打开串口 self.ser = serial.Serial('COM7', 9600, timeout=1) def initUI(self): # 创建用于显示员工信息的控件 self.info_label = QLabel("员工信息", self) self.info_label.move(100, 50) self.info_label.setStyleSheet("font-size: 24px; color: black; background-color: #eee; border-radius: 10px;") self.id_label = QLabel("员工ID:", self) self.id_label.move(70, 100) self.id_label.setStyleSheet("font-size: 18px; color: black;") self.name_label = QLabel("姓名:", self) self.name_label.move(70, 150) self.name_label.setStyleSheet("font-size: 18px; color: black;") self.six_label = QLabel("性别:", self) self.six_label.move(70, 200) self.six_label.setStyleSheet("font-size: 18px; color: black;") self.sfz_label = QLabel("身份证:", self) self.sfz_label.move(70, 250) self.sfz_label.setStyleSheet("font-size: 18px; color: black;") self.tel_label = QLabel("电话:", self) self.tel_label.move(70, 300) self.tel_label.setStyleSheet("font-size: 18px; color: black;") self.setFixedSize(800, 500) self.setWindowTitle('员工信息') # 查询员工信息 def query_employee(self, id): conn = pymysql.connect(host='39.99.214.172', user='root', password='Solotion.123', database='jj_tset') cursor = conn.cursor() cursor.execute("SELECT * FROM employee_table WHERE user_id='%s'" % id) result = cursor.fetchone() conn.close() return result # 读取数据 def read_data(self): data = self.ser.readline() if data: # 解析数据 id = data.decode().strip() # 查询员工信息 result = self.query_employee(id) if result: # 更新UI界面 self.id_label.setText("员工ID:" + result[0]) self.name_label.setText("姓名:" + str(result[1])) self.six_label.setText("性别:" + result[2]) self.sfz_label.setText("身份证:" + str(result[3])) self.tel_label.setText("电话:" + result[4]) print(result[0],result[1],result[2],result[3],result[4]) else: # 显示空白信息 self.id_label.setText("员工ID:") self.name_label.setText("姓名:") self.six_label.setText("性别:") self.sfz_label.setText("身份证:") self.tel_label.setText("电话:") # 定时读取数据 QTimer.singleShot(100, self.read_data) def closeEvent(self, event): # 关闭串口 self.ser.close()把这个改为多线程

button = QPushButton('开始称重', login_widget) button.move(100, 100) button.setGeometry(300, 200, 200, 50) button.clicked.connect()点击后怎么调用新的.py文件中class MainWindow(QMainWindow): def init(self, user_id): super().init() self.user_id = user_id self.initUI() # 打开串口 self.ser = serial.Serial('COM7', 9600, timeout=1) def initUI(self): # 创建用于显示员工信息的控件 self.info_label = QLabel("员工信息", self) self.info_label.move(100, 50) self.info_label.setStyleSheet("font-size: 24px; color: black; background-color: #eee; border-radius: 10px;") self.id_label = QLabel("员工ID:", self) self.id_label.move(70, 100) self.id_label.setStyleSheet("font-size: 18px; color: black;") self.name_label = QLabel("姓名:", self) self.name_label.move(70, 150) self.name_label.setStyleSheet("font-size: 18px; color: black;") self.six_label = QLabel("性别:", self) self.six_label.move(70, 200) self.six_label.setStyleSheet("font-size: 18px; color: black;") self.sfz_label = QLabel("身份证:", self) self.sfz_label.move(70, 250) self.sfz_label.setStyleSheet("font-size: 18px; color: black;") self.tel_label = QLabel("电话:", self) self.tel_label.move(70, 300) self.tel_label.setStyleSheet("font-size: 18px; color: black;") self.setFixedSize(800, 500) self.setWindowTitle('员工信息') # 查询员工信息 def query_employee(self, id): conn = pymysql.connect(host='39.99.214.172', user='root', password='Solotion.123', database='jj_tset') cursor = conn.cursor() cursor.execute("SELECT * FROM employee_table WHERE user_id='%s'" % id) result = cursor.fetchone() conn.close() return result # 读取数据 def read_data(self): data = self.ser.readline() if data: # 解析数据 id = data.decode().strip() # 查询员工信息 result = self.query_employee(id) if result: # 更新UI界面 self.id_label.setText("员工ID:" + result[0]) self.name_label.setText("姓名:" + str(result[1])) self.six_label.setText("性别:" + result[2]) self.sfz_label.setText("身份证:" + str(result[3])) self.tel_label.setText("电话:" + result[4]) print(result[0],result[1],result[2],result[3],result[4]) else: # 显示空白信息 self.id_label.setText("员工ID:") self.name_label.setText("姓名:") self.six_label.setText("性别:") self.sfz_label.setText("身份证:") self.tel_label.setText("电话:") # 定时读取数据 QTimer.singleShot(100, self.read_data) def closeEvent(self, event): # 关闭串口 self.ser.close()

class MainWindow(QMainWindow): def init(self): super().init() # 设置主窗口大小 self.setFixedSize(800, 600) # 创建主窗口布局 main_layout = QVBoxLayout() central_widget = QWidget() central_widget.setLayout(main_layout) self.setCentralWidget(central_widget) # 创建两个竖向按钮 button_layout = QVBoxLayout() button1 = QPushButton('当日员工工资') button1.setFixedSize(200, 50) button1.clicked.connect(self.show_query1_result) button2 = QPushButton('当日鸡爪领取记录') button2.setFixedSize(200, 50) button2.clicked.connect(self.show_query2_result) button3 = QPushButton('查询历史员工工资') button3.setFixedSize(200, 50) button3.clicked.connect(self.show_query3_result) button4 = QPushButton('查询历史鸡爪领取记录') button4.setFixedSize(200, 50) button4.clicked.connect(self.show_query4_result) button_layout.addStretch() button_layout.addWidget(button1) button_layout.addWidget(button2) button_layout.addWidget(button3) button_layout.addWidget(button4) button_layout.addStretch() layout = QHBoxLayout() layout.addStretch() layout.addLayout(button_layout) layout.addStretch() widget = QWidget() widget.setLayout(layout) self.setCentralWidget(widget) # 将按钮布局添加到主窗口布局中 main_layout.addLayout(button_layout) # 创建两个窗口用于展示查询结果 self.query1_window = QueryResultWindow() self.query2_window = QueryResultWindow() self.query3_window = QueryResultWindow() self.query4_window = QueryResultWindow() def show_query1_result(self): # 查询数据 db = pymysql.connect(host='39.99.214.172', user='root', password='Solotion.123', db='jj_tset') cursor = db.cursor() db_sql = """ """ cursor.execute(db_sql) result = cursor.fetchall() db.close() if len(result) == 0: QMessageBox.information(self, "提示", "今日无员工工资记录") return # 清空表格 self.query1_window.table_widget.setRowCount(0) self.query1_window.table_widget.setColumnCount(len(result[0])) self.query1_window.table_widget.setHorizontalHeaderLabels \ (["员工ID", "员工姓名", "日期", "领取鸡爪重量(KG)", "效率(每小时KG)", "出成率", "基础工资", "重量奖励", "当日总工资"]) # 添加数据到表格 for row_num, row_data in enumerate(result): self.query1_window.table_widget.insertRow(row_num) for col_num, col_data in enumerate(row_data): self.query1_window.table_widget.setItem(row_num, col_num, QTableWidgetItem(str(col_data))) # 显示窗口 self.query1_window.show()数据展示页面怎么设置筛选器按ID筛选结果并展示

下列代码中,self.button没有正常显示,“import sys import cv2 import numpy as np # from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton, QVBoxLayout, QWidget, QFormLayout,QComboBox from PyQt5.QtWidgets import * from PyQt5.QtGui import QIcon, QPainter, QBrush, QPen, QColor, QPixmap from PyQt5.QtCore import Qt, QSize, QRect, QTimer from PyQt5 import QtCore, QtGui, QtWidgets import os from PyQt5.QtCore import QPropertyAnimation, QRect, QEasingCurve class DynamicLabel(QLabel): def __init__(self, text, parent=None): super().__init__(text, parent) self.setAlignment(Qt.AlignCenter) # 设置文字居中 self.setStyleSheet("color: green;") QTimer.singleShot(100, self.adjust_font_size) self.resizeEvent = self.on_resize # 绑定窗口大小变化事件 def adjust_font_size(self): font_size = int(self.height() * 0.8) self.setStyleSheet(f"min-height: 60px;color: green; font-size: {font_size}px;font-weight: bold;") def on_resize(self, event): super().resizeEvent(event) self.adjust_font_size() # 窗口大小变化时重新计算 class CircularButton(QPushButton): def __init__(self, normal_icon, pressed_icon, parent=None): super().__init__(parent) # 设置按钮固定大小确保圆形 # self.setFixedSize(50, 50) # 图标设置 self.normal_icon = QIcon(normal_icon) self.pressed_icon = QIcon(pressed_icon) # 初始状态 self.setIcon(self.normal_icon) self.setIconSize(QSize(30, 30)) self.is_pressed = False # 应用初始样式 self.update_style() def update_style(self): """根据按钮状态更新样式""" radius = self.width() // 2 # 圆形半径 if self.is_pressed: # 按下状态:绿色背景,显示按下图标 self.setIcon(self.pressed_icon) style = f""" QPushButton {{ background-color: #4CAF50; /* 绿色背景 */ border: 2px solid #CCCCCC; min-width: 80px; min-height: 40px; border-radius: 20px; /* 圆角半径 */ }} QPushButton:hover {{ background-color: #388E3C; }} """ else: # 正常状态:透明背景,显示正常图标 self.setIcon(self.normal_icon) style = f""" QPushButton {{ background-color: transparent; min-width: 50px; min-height: 40px; border-radius: {radius}px; border-radius: 20px; /* 圆角半径 */ }} QPushButton:hover {{ border-color: #007BFF; background-color: rgba(0, 123, 255, 0.1); }} """ self.setStyleSheet(style) def mousePressEvent(self, event): """鼠标按下事件处理""" if event.button() == Qt.LeftButton: self.is_pressed = not self.is_pressed # 切换状态 self.update_style() super().mousePressEvent(event) def resizeEvent(self, event): """调整大小时保持圆形""" self.update_style() super().resizeEvent(event) class MainWindow(QMainWindow): def __init__(self): super().__init__() # 调用父类构造函数 self.setWindowTitle("实时摄像头显示") # 设置窗口标题 self.setGeometry(100, 100, 800, 600) # 设置窗口位置和大小 # 创建主布局 central_widget = QWidget() # central_widget.setStyleSheet('background:blue') self.setCentralWidget(central_widget) # self.btn = CircularButton( # normal_icon="D:/icon/lock.png", # 替换为您的图标路径 # pressed_icon="D:/icon/unlock.png" # 替换为您的图标路径 # ) # 创建容器用于放置滑动按钮 self.container = QWidget() self.container.setObjectName("B1") self.container.setGeometry(50, 25, 104, 54) self.container.setStyleSheet("#B1 {background-color: #DC143C;border-radius: 25px;}") # 创建可滑动的按钮 self.button = QPushButton(self.container) self.button.setIcon(QIcon("E:/1TUF/上鎖.png")) self.button.setGeometry(2, 2, 50, 50) self.button.setStyleSheet(""" QPushButton { background-color:#FFFFFF; border-radius: 25px; border: none; } QPushButton:hover { background-color: #64b5f6; } """) self.button.clicked.connect(self.slide_button) # 动画设置 self.animation = QPropertyAnimation(self.button, b"geometry") self.animation.setDuration(100) # 动画持续时间(毫秒) self.animation.setEasingCurve(QEasingCurve.Linear) # 弹性效果 # 状态跟踪 # self.is_left = True # 初始状态在左侧 # 连接信号 # self.btn.clicked.connect(self.on_button_click) leftframe,rightframe = QFrame(), QFrame() rightframe.setObjectName("rightframe") le_label = QLabel(leftframe) le_label.setObjectName("le_label") # le_label.setStyleSheet('border:1px solid blue') le_label.setStyleSheet("#le_label{ border: 1px solid red; }") rightframe.setStyleSheet("#rightframe{ border: 1px solid red; }") testresult = DynamicLabel("PASS") leftlayout = QVBoxLayout() rightlayout = QVBoxLayout() le_label.setLayout(leftlayout), rightframe.setLayout(rightlayout) leftlayout.addWidget(self.container, alignment=Qt.AlignCenter) labels = {"label1":"white", "线别名称":"white", "FIXID":"white","机种名称":"white", "投产90":"white"} left_style = "background-color: lightgray; border-bottom: 2px solid black;" self.great_label(leftlayout, labels, left_style) testinfotop = {"摄像头\ncamera": "5", "RFID状态\nRFID status": "yellow", "ISN": "pink", "测试工单\nTest MO": "blue"} testinfobot = { "投产总数": "green","PASS数": "yellow", "不良数": "red", "直通率": "red"} self.great_labelHtext(rightlayout, testinfotop, left_style) self.great_labelHlcdnumber(rightlayout, testinfobot, left_style) rightlayout.insertWidget(0, testresult, 2) centerlayout = QHBoxLayout() video = QLabel("视频区域", self) video.setStyleSheet(" border: 1px solid red;") centerlayout.addWidget(le_label, 2) centerlayout.addWidget(video, 8) centerlayout.addWidget(rightframe, 2) mainlayout = QVBoxLayout(central_widget) toprap = QLabel("头部区域", self) toprap.setStyleSheet(" border: 1px solid red;") mainlayout.addWidget(toprap,1) mainlayout.addLayout(centerlayout,8) botrap = QLabel("底部区域", self) botrap.setStyleSheet(" border: 1px solid red;") mainlayout.addWidget(botrap, 3) self.setLayout(mainlayout) def slide_button(self): """切换按钮位置并启动动画""" if self.is_left: self.container.setStyleSheet("#B1 {background-color: #00FA9A;border-radius: 25px;}") self.button.setIcon(QIcon("../icon/unlock.png")) # 滑动到右侧 (150 = 容器宽度200 - 按钮宽度50) self.animation.setStartValue(QRect(2, 2, 50, 50)) self.animation.setEndValue(QRect(52, 2, 50, 50)) print(f"按钮状态: 開") else: # 滑动回左侧 self.container.setStyleSheet("#B1 {background-color: #DC143C;border-radius: 25px;}") self.button.setIcon(QIcon("../icon/lock.png")) self.animation.setStartValue(QRect(52, 2, 50, 50)) self.animation.setEndValue(QRect(2, 2, 50, 50)) print(f"按钮状态: 関") self.animation.start() self.is_left = not self.is_left # 切换状态 def great_labelHtext(self, parelayout, labels, left_style, framestyle="background-color: lightgray"): for key, item in labels.items(): # 创建一个 QFrame 作为容器 frame = QFrame() frame.setStyleSheet(f"{framestyle}") labellayout = QBoxLayout(QBoxLayout.LeftToRight) l1 = QLabel(key, self) l2 = QLineEdit(item, self) l2.setStyleSheet(f"{left_style}") labellayout.addWidget(l1, 4) labellayout.addWidget(l2, 6) frame.setLayout(labellayout) parelayout.addWidget(frame,1) def great_labelHlcdnumber(self, parelayout, labels, left_style, framestyle="background-color: lightgray"): for key, item in labels.items(): # 创建一个 QFrame 作为容器 frame = QFrame() frame.setStyleSheet(f"QFrame {framestyle}") labellayout = QBoxLayout(QBoxLayout.LeftToRight) l1 = QLabel(key, self) l2 = QLCDNumber(5, self) l2.setSegmentStyle(QLCDNumber.Flat) l2.setStyleSheet(""" QLCDNumber { border: 2px solid #87CEEB; color: #00bfff; background: #b0e2ff; } """) labellayout.addWidget(l1) labellayout.addWidget(l2) frame.setLayout(labellayout) parelayout.addWidget(frame,1) def great_label(self, parelayout, labels, left_style, framestyle="background-color: lightgray"): for key,item in labels.items(): # 创建一个 QFrame 作为容器 frame = QFrame() frame.setStyleSheet(f"{framestyle}") labellayout = QBoxLayout(QBoxLayout.TopToBottom) l1 = QLabel(key,self) l2 = QLabel(item,self) l2.setStyleSheet(f"{left_style}") labellayout.addWidget(l1) labellayout.addWidget(l2) frame.setLayout(labellayout) parelayout.addWidget(frame) if __name__ == '__main__': app = QApplication(sys.argv) # 创建应用程序实例 window = MainWindow() # 创建主窗口实例 window.show() # 显示主窗口 sys.exit(app.exec_()) # 运行应用程序并等待退出”

class MyApp(QMainWindow): signal = pyqtSignal(str, str, int, str) def init(self, parent= None): super(MyApp, self).init(parent) self.setWindowTitle("Matplotlib in PyQt6") MainWindow.resize(self, 800, 600) self.star() self.initUI() def star(self): btn1 = QPushButton("Button 1", self) btn1.move(30, 50) btn2 = QPushButton("Button 2", self) btn2.move(150, 50) btn1.clicked.connect(self.buttonClicked1) btn2.clicked.connect(self.buttonClicked2) # create textbox self.textbox1 = QLineEdit(self) self.textbox1.setText("123") self.textbox2 = QLineEdit(self) self.textbox1.move(20, 20) self.textbox1.resize(280, 40) self.textbox2.move(20, 150) self.textbox2.resize(280, 40) self.show() def initUI(self): # 创建一个QWidget对象 central_widget = QWidget(self) # 将该QWidget设置为主窗口的中心组件 self.setCentralWidget(central_widget) # 创建需要显示的QWidget组件,例如QPushButton和QLabel button = QPushButton("Button", central_widget) label = QLabel("Label", central_widget) label.setFixedSize(100, 10) # 创建一个Matplotlib的Figure对象 self.figure = Figure(figsize=(5, 4), dpi=100) # 在Figure中添加一个Axes对象 self.axes = self.figure.add_subplot(111) self.axes.set_xlabel("X-axis") self.axes.set_ylabel("Y-axis") self.axes.set_title("Matplotlib in PyQt6") # 创建一个FigureCanvas对象,并将其放置在QWidget中 canvas = FigureCanvas(self.figure) canvas.resize(self, 200, 100) canvas.updateGeometry() # 将FigureCanvas添加到QWidget中 central_widget = QWidget(self) self.setCentralWidget(central_widget) # 创建一个QVBoxLayout对象,将需要显示的QWidget组件添加到其中 layout = QVBoxLayout(central_widget) layout.addWidget(button) layout.addWidget(label) layout.addWidget(label) layout.addWidget(canvas) @pyqtSlot() def buttonClicked1(self): text = self.textbox1.text() self.statusBar().showMessage(text) @pyqtSlot() def buttonClicked2(self): text = self.textbox1.text() self.textbox2.setText(text) self.statusBar().showMessage(text)如何把def sta里的textbox获得的参数通过他的监听把参数传值到def init上,使得def init 上可以获得外部的值作为变量传入调用

最新推荐

recommend-type

Qt开发:XML文件读取、滚动区域控件布局与多Sheet Excel保存的界面设计实例

内容概要:本文介绍了基于Qt框架的界面设计例程,重点讲解了三个主要功能模块:一是利用XML文件进行配置信息的读取并初始化界面组件;二是实现了滚动区域内的灵活控件布局,在空间不足时自动生成滚动条以扩展显示范围;三是提供了将界面上的数据导出到带有多个工作表的Excel文件的功能。文中还提及了所用IDE的具体版本(Qt Creator 4.8.0 和 Qt 5.12.0),并且强调了这些技术的实际应用场景及其重要性。 适合人群:对Qt有初步了解,希望深入学习Qt界面设计技巧的开发者。 使用场景及目标:适用于需要快速构建复杂用户界面的应用程序开发,特别是那些涉及大量数据展示和交互的设计任务。通过学习本文提供的案例,可以提高对于Qt框架的理解,掌握更多实用技能。 其他说明:为了帮助读者更好地理解和实践,作者推荐前往B站观看高清的教学视频,以便于更直观地感受整个项目的开发流程和技术细节。
recommend-type

锂电池保护板方案:中颖SH367309原理图与PCB源代码详解及应用技巧

基于中颖SH367309芯片的锂电池保护板设计方案,涵盖原理图解析、PCB布局优化、硬件选型要点以及软件编程技巧。重点讨论了电流检测精度、过压保护阈值设定、通信协议处理和温度传感器布置等方面的实际开发经验和技术难点。文中还分享了一些实用的小贴士,如采用星型接地减少干扰、利用过孔阵列降低温升、为MOS管增加RC缓冲避免高频振荡等。 适合人群:从事锂电池管理系统(BMS)开发的技术人员,尤其是有一定硬件设计基础并希望深入了解具体实现细节的工程师。 使用场景及目标:帮助开发者掌握锂电池保护板的关键技术和常见问题解决方案,确保产品在各种工况下都能安全可靠运行,同时提高系统性能指标如效率、响应速度和稳定性。 阅读建议:由于涉及较多底层硬件知识和实战案例,建议读者结合自身项目背景进行针对性学习,在遇到类似问题时能够快速定位原因并找到有效对策。此外,对于初学者来说,可以从简单的电路搭建开始逐步深入研究复杂的功能模块。
recommend-type

PHP资格证书查询系统:基于FastAdmin框架的二维码生成与表单验证

内容概要:本文介绍了基于PHP开发的资格证书查询系统,详细阐述了其核心功能和技术实现。系统主要功能包括自动生成二维码、支持导入导出功能、表单验证以及手机端查询和后端登录编辑。该系统采用FastAdmin框架开发,确保了高效的开发流程和良好的用户体验。此外,文中还提到了系统所需的环境要求,如PHP版本需>=7.1且<=5.5.3,支持InnoDB引擎和伪静态设置。最后,通过一段PHP代码示例展示了如何实现自动生成二维码的功能。 适合人群:具备一定PHP开发经验的技术人员,尤其是对FastAdmin框架感兴趣的开发者。 使用场景及目标:适用于需要管理和查询资格证书的企业和个人。目标是提高证书管理效率,增强用户体验,确保数据安全。 其他说明:该系统不仅实现了基本的证书管理功能,还通过引入二维码技术和表单验证提升了系统的实用性和安全性。
recommend-type

PLC与ETHERCAT总线控制的H5U程序框架详解及其广泛应用

H5U程序框架,这是一个针对PLC系统(如汇川、三菱、台达等)的通用模板,特别强调了对ETHERCAT总线的应用。文章解析了气缸控制、轴控制的状态机逻辑以及故障恢复机制,并展示了清晰的注释和硬件抽象层的设计。气缸控制部分涵盖了伸出、缩回、报警等功能,而轴控制则细分为多个步骤,包括通讯建立、使能、JOG、绝对定位等。此外,文中提供了具体的代码片段来解释各个功能模块的工作原理。 适合人群:从事工业自动化领域的工程师和技术人员,尤其是那些需要理解和实施PLC控制系统的人群。 使用场景及目标:①帮助工程师快速掌握H5U程序框架的使用方法;②为实际工程项目提供可靠的代码参考;③提高PLC程序的可移植性和维护性。 其他说明:该框架因其良好的设计和详细的注释,在工控圈中备受推崇,被认为是‘万金油’级别的解决方案。
recommend-type

c语言学生信息系统.zip

C语言项目源码
recommend-type

Web前端开发:CSS与HTML设计模式深入解析

《Pro CSS and HTML Design Patterns》是一本专注于Web前端设计模式的书籍,特别针对CSS(层叠样式表)和HTML(超文本标记语言)的高级应用进行了深入探讨。这本书籍属于Pro系列,旨在为专业Web开发人员提供实用的设计模式和实践指南,帮助他们构建高效、美观且可维护的网站和应用程序。 在介绍这本书的知识点之前,我们首先需要了解CSS和HTML的基础知识,以及它们在Web开发中的重要性。 HTML是用于创建网页和Web应用程序的标准标记语言。它允许开发者通过一系列的标签来定义网页的结构和内容,如段落、标题、链接、图片等。HTML5作为最新版本,不仅增强了网页的表现力,还引入了更多新的特性,例如视频和音频的内置支持、绘图API、离线存储等。 CSS是用于描述HTML文档的表现(即布局、颜色、字体等样式)的样式表语言。它能够让开发者将内容的表现从结构中分离出来,使得网页设计更加模块化和易于维护。随着Web技术的发展,CSS也经历了多个版本的更新,引入了如Flexbox、Grid布局、过渡、动画以及Sass和Less等预处理器技术。 现在让我们来详细探讨《Pro CSS and HTML Design Patterns》中可能包含的知识点: 1. CSS基础和选择器: 书中可能会涵盖CSS基本概念,如盒模型、边距、填充、边框、背景和定位等。同时还会介绍CSS选择器的高级用法,例如属性选择器、伪类选择器、伪元素选择器以及选择器的组合使用。 2. CSS布局技术: 布局是网页设计中的核心部分。本书可能会详细讲解各种CSS布局技术,包括传统的浮动(Floats)布局、定位(Positioning)布局,以及最新的布局模式如Flexbox和CSS Grid。此外,也会介绍响应式设计的媒体查询、视口(Viewport)单位等。 3. 高级CSS技巧: 这些技巧可能包括动画和过渡效果,以及如何优化性能和兼容性。例如,CSS3动画、关键帧动画、转换(Transforms)、滤镜(Filters)和混合模式(Blend Modes)。 4. HTML5特性: 书中可能会深入探讨HTML5的新标签和语义化元素,如`<article>`、`<section>`、`<nav>`等,以及如何使用它们来构建更加标准化和语义化的页面结构。还会涉及到Web表单的新特性,比如表单验证、新的输入类型等。 5. 可访问性(Accessibility): Web可访问性越来越受到重视。本书可能会介绍如何通过HTML和CSS来提升网站的无障碍访问性,比如使用ARIA标签(Accessible Rich Internet Applications)来增强屏幕阅读器的使用体验。 6. 前端性能优化: 性能优化是任何Web项目成功的关键。本书可能会涵盖如何通过优化CSS和HTML来提升网站的加载速度和运行效率。内容可能包括代码压缩、合并、避免重绘和回流、使用Web字体的最佳实践等。 7. JavaScript与CSS/HTML的交互: 在现代Web开发中,JavaScript与CSS及HTML的交云并用是不可或缺的。书中可能会讲解如何通过JavaScript动态地修改样式、操作DOM元素以及使用事件监听和响应用户交互。 8. Web框架和预处理器: 这本书可能会提到流行的Web开发框架和预处理器,比如Bootstrap、Foundation、Sass和Less等,它们是如何简化和加速开发流程的。 9. 测试和维护: 书中也可能包含关于如何测试网页以及如何持续优化和维护CSS和HTML代码的章节。例如,使用断言测试、自动化测试、性能分析工具等。 最后,鉴于文件名称列表中的“压缩包子文件”的表述,这可能是对“压缩包”文件的一种误译或误用,此处“压缩包”应该指的是包含该书籍PDF文件的压缩文件格式,如ZIP或RAR。而“Pro CSS and HTML Design Patterns.pdf”指的就是该书籍的PDF格式电子版文件。 以上所述,构成了《Pro CSS and HTML Design Patterns》一书可能包含的核心知识点。通过学习这些内容,Web前端开发者可以掌握更为高效和优雅的设计模式,从而在日常工作中更高效地解决实际问题。
recommend-type

Zotero 7数据同步:Attanger插件安装&设置,打造文献管理利器

/i.s3.glbimg.com/v1/AUTH_08fbf48bc0524877943fe86e43087e7a/internal_photos/bs/2018/L/j/ipKA8TRPyt4ptaG1DGww/t-m-01.png) # 1. Zotero 7数据同步简介 在数字时代,管理研究数据变得日益重要,而Zot
recommend-type

卷积神经网络的基础理论200字

<think>我们正在回答用户关于卷积神经网络(CNN)基础理论的询问。根据提供的引用资料,我们可以概述CNN的基本结构和工作原理。引用[1]提到CNN是一种前馈神经网络,信息从输入单向流动到输出。引用[2]指出CNN在图像处理等领域应用广泛,通过层次结构和参数调整实现模式识别。引用[3]说明CNN包含卷积层,使用卷积核提取局部特征,减少参数量,提高效率。引用[4]则提到了训练过程,包括前向传播、误差计算和反向传播(梯度下降)。因此,我们将从以下几个方面概述CNN:1.CNN的基本结构(卷积层、池化层、全连接层)2.卷积操作的工作原理(局部感受野、权重共享)3.训练过程(前向传播、损失函数、反
recommend-type

轻便实用的Java库类查询工具介绍

标题 "java2库类查询" 和描述表明,所提及的工具是一个专门用于查询Java库类的应用程序。此软件旨在帮助开发者快速地查找和引用Java的标准开发工具包(SDK)中包含的所有应用程序编程接口(API)类。通过这样的工具,开发者可以节省大量在官方文档或搜索引擎上寻找类定义和使用方法的时间。它被描述为轻巧且方便,这表明其占用的系统资源相对较少,同时提供直观的用户界面,使得查询过程简洁高效。 从描述中可以得出几个关键知识点: 1. Java SDK:Java的软件开发工具包(SDK)是Java平台的一部分,提供了一套用于开发Java应用软件的软件包和库。这些软件包通常被称为API,为开发者提供了编程界面,使他们能够使用Java语言编写各种类型的应用程序。 2. 库类查询:这个功能对于开发者来说非常关键,因为它提供了一个快速查找特定库类及其相关方法、属性和使用示例的途径。良好的库类查询工具可以帮助开发者提高工作效率,减少因查找文档而中断编程思路的时间。 3. 轻巧性:软件的轻巧性通常意味着它对计算机资源的要求较低。这样的特性对于资源受限的系统尤为重要,比如老旧的计算机、嵌入式设备或是当开发者希望最小化其开发环境占用空间时。 4. 方便性:软件的方便性通常关联于其用户界面设计,一个直观、易用的界面可以让用户快速上手,并减少在使用过程中遇到的障碍。 5. 包含所有API:一个优秀的Java库类查询软件应当能够覆盖Java所有标准API,这包括Java.lang、Java.util、Java.io等核心包,以及Java SE平台的所有其他标准扩展包。 从标签 "java 库 查询 类" 可知,这个软件紧密关联于Java编程语言的核心功能——库类的管理和查询。这些标签可以关联到以下知识点: - Java:一种广泛用于企业级应用、移动应用(如Android应用)、网站后端、大型系统和许多其他平台的编程语言。 - 库:在Java中,库是一组预打包的类和接口,它们可以被应用程序重复使用。Java提供了庞大的标准库,以支持各种常见的任务和功能。 - 查询:查询指的是利用软件工具搜索、定位和检索信息的过程。对于Java库类查询工具来说,这意味着可以通过类名、方法签名或其他标识符来查找特定的API条目。 最后,压缩包文件列表包含了两个文件:“java.dit”和“Java.exe”。其中“Java.exe”很可能是程序的可执行文件,而“java.dit”可能是一个数据文件,用于存储Java类的索引或数据。由于文件名后缀通常与文件类型相关联,但“dit”并不是一个常见的文件扩展名。这可能是一个特定于软件的自定义格式,或是一个打字错误。 总结来说,"java2库类查询" 是一个针对Java开发者的实用工具,它提供了一个轻量级、易用的平台来查询和定位Java标准库中的所有类和API。此工具对优化开发流程,减少查找Java类文档的时间大有裨益,尤其适合需要频繁查阅Java API的开发者使用。
recommend-type

【Zotero 7终极指南】:新手必备!Attanger插件全攻略与数据同步神技

# 1. Zotero 7与Attanger插件的介绍 在当今的学术研究和知识管理领域,高效的文献管理工具至关重要。Zotero 7作为一个流行的参考文献管理软件,因其强大的功能和用户友好的界面而受到专业人士的青睐。而Attanger插件则为Zotero 7带来了更多定制化和高级功能,极大地增强