首页 / 资讯中心 / 文章详情

基于Flask+Vue.js+YOLOv9的智能轴承缺陷检测系统

基于Flask+Vue.js+YOLOv9的智能轴承缺陷检测系统 ★ FEATURED ARTICLE
一、项目概述1.1 项目名称轴承缺陷检测系统Bearing Defect Detection System1.2 项目简介系统是一个基于YOLOv9深度学习算法的智能轴承缺陷检测平台采用前后端分离架构实现对轴承表面缺陷的自动化识别与管理。系统支持图像上传、摄像头实时检测和视频检测三种方式能够准确识别铸造毛刺、裂纹、划痕、凹坑等8种缺陷类型。1.3 技术栈前端Vue.js 3.2.13、Vue Router 4.6.3、Axios 1.12.2后端Flask 3.0.3、Flask-SQLAlchemy、Flask-JWT-Extended深度学习YOLOv9、PyTorch 2.0、OpenCV 4.8数据库SQLite。二、系统架构2.1 整体架构系统采用前后端分离的B/S架构前端Vue.js单页应用提供用户交互界面后端Flask RESTful API服务处理业务逻辑AI模型YOLOv9目标检测模型负责缺陷识别数据库SQLite存储用户信息和检测记录。2.2 目录结构项目根目录/ ├── fxapp-frontend/ # 前端Vue项目 │ ├── src/ │ │ ├── views/ # 页面组件 │ │ ├── services/ # API服务 │ │ ├── router/ # 路由配置 │ │ └── App.vue # 根组件 │ └── package.json ├── fxapp-backend/ # 后端Flask项目 │ ├── app.py # 主应用文件 │ └── instance/ # 数据库文件 ├── yolov9-main/ # YOLOv9模型 │ ├── data1/ # 训练数据集 │ └── runs/ # 训练结果 └── requirements.txt # Python依赖三、功能模块3.1 用户管理模块用户注册用户名、手机号、密码注册支持手机号格式验证用户登录支持普通用户和管理员登录JWT Token认证权限控制普通用户查看个人数据管理员管理全局数据。# 用户登录 app.route(/api/login, methods[POST]) def login(): data request.get_json() username data[username] password data[password] # 检查管理员 if username admin and password admin123: access_token create_access_token( identity{username: admin, is_admin: True, id: 0} ) return jsonify({access_token: access_token}), 200 # 普通用户验证 user User.query.filter_by(usernameusername).first() if user and user.check_password(password): access_token create_access_token(identity{username: user.username, id: user.id}) return jsonify({access_token: access_token, user: user.to_dict()}), 2003.2 缺陷检测模块图像上传检测支持JPG/PNG/BMP格式最大16MB拖拽上传摄像头实时检测调用设备摄像头实时拍照检测缺陷识别识别8种轴承缺陷铸造毛刺、裂纹、划痕、凹坑、抛光铸件、应变、未抛光铸件、毛刺结果展示标注图像、缺陷类型、置信度、坐标信息。# 缺陷检测 def detect_violation(image_path): # 加载模型 yolo_model torch.hub.load(../yolov9-main, custom, pathmodel_path, sourcelocal) yolo_model.conf 0.25 # 读取图像并检测 img cv2.imread(image_path) results yolo_model(img) detections results.pandas().xyxy[0] # 解析结果 detected_objects {defects: []} for idx, row in detections.iterrows(): defect_type translate_label_to_chinese(row[name]) detected_objects[defects].append({ type: defect_type, confidence: float(row[confidence]), bbox: [int(row[xmin]), int(row[ymin]), int(row[xmax]), int(row[ymax])] }) return {violation_type: defect_type, detected_objects: detected_objects}3.3 记录管理模块记录列表分页显示、按类型筛选、批量删除记录详情查看标注图像和详细信息。# 获取记录列表 app.route(/api/violations/records, methods[GET]) jwt_required() def get_violation_records(): current_user get_jwt_identity() page request.args.get(page, 1, typeint) # 查询记录 query ViolationRecord.query.filter_by(user_idcurrent_user[id]) pagination query.order_by(ViolationRecord.created_at.desc()).paginate(pagepage, per_page10) return jsonify({ records: [record.to_dict() for record in pagination.items], total: pagination.total }), 2003.4 统计分析模块用户统计总记录数、活跃天数、平均置信度、本月检测次数管理员统计用户总数、缺陷分布图、7天趋势图。# 获取统计数据 app.route(/api/violations/statistics, methods[GET]) jwt_required() def get_violation_statistics(): current_user get_jwt_identity() # 总数统计 total_violations ViolationRecord.query.filter_by(user_idcurrent_user[id]).count() # 按类型统计 violation_by_type db.session.query( ViolationRecord.violation_type, func.count(ViolationRecord.id).label(count) ).filter_by(user_idcurrent_user[id]).group_by(ViolationRecord.violation_type).all() # 平均置信度 avg_confidence db.session.query( func.avg(ViolationRecord.confidence) ).filter_by(user_idcurrent_user[id]).scalar() return jsonify({ total_violations: total_violations, violation_by_type: [{type: t, count: c} for t, c in violation_by_type], avg_confidence: round(float(avg_confidence), 2) }), 200四、数据库设计4.1 用户表User字段名类型说明idinteger主键usernameString(80)用户名唯一phonetring(11)手机号唯一password_hashString(60)密码哈希is_adminBoolean是否管理员created_atDateTime创建时间4.2 违章记录表ViolationRecord字段名类型说明idInteger主键user_idInteger用户ID外键image_pathString(255)图像路径Base64vehicle_typeString(50)车辆类型plate_numberString(20)车牌号violation_typeString(100)违章类型confidenceFloat置信度locationString(255)地点descriptionText描述detected_objectsText检测对象JSONcreated_atDateTime创建时间五、YOLOv9模型配置5.1 数据集配置data1.yaml path: C:/Users/admin/Desktop/yolov9-main/data1 train: images/train # 2559张训练图像 val: images/val # 732张验证图像 nc: 8 # 8个类别 names: 0: Casting_burr 1: crack 2: scratch 3: pit 4: Polished_casting 5: strain 6: unpolished_casting 7: burr5.2 模型参数置信度阈值0.25NMS IOU阈值0.45模型路径../yolov9-main/runs/train/exp/weights/best.pt5.3 检测流程加载YOLOv9模型 -- 读取输入图像 -- 执行目标检测 -- 解析检测结果 -- 绘制标注框和中文标签 -- 保存标注图像 -- 返回检测结果六、部署说明6.1 环境要求Python 3.8Node.js 14支持CUDA的GPU可选用于加速6.2 后端部署# 安装依赖 pip install -r requirements.txt # 运行后端服务 cd fxapp-backend python app.py # 服务运行在 http://localhost:50006.3 前端部署# 安装依赖 cd fxapp-frontend npm install # 开发模式运行 npm run serve # 访问 http://localhost:8080 # 生产构建 npm run build6.4 默认账户管理员账户用户名admin密码admin123七、视频演示轴承缺陷检测
阅读完成 · 觉得有帮助?
咨询建站