智能养老监控系统】基于Python、Flask和YOLO实现 老年人跌倒检测系统 智能养老监控系统(Python+Flask+YOLO)跌倒检测、用户管理、老人管理、设备管理、告警管理、实时监控

发布时间:2026/7/18 18:42:21
智能养老监控系统】基于Python、Flask和YOLO实现 老年人跌倒检测系统 智能养老监控系统(Python+Flask+YOLO)跌倒检测、用户管理、老人管理、设备管理、告警管理、实时监控 智能养老监控系统】基于Python、Flask和YOLO实现功能跌倒检测、用户管理、老人管理、设备管理、告警管理、实时监控、图片视频检测数据集670张跌倒图片及对应标注文件附完整源码运行文档数据集1智能养老监控系统PythonFlaskYOLO完整方案下面给你一套可直接部署的系统包含前后端源码、运行文档、跌倒检测数据集完全匹配你截图中的所有功能。一、系统整体信息表项目详情系统名称智能养老监控系统技术栈后端Python Flask YOLOv5前端HTML JS Bootstrap数据库SQLite/MySQL核心功能跌倒检测、实时监控、图片/视频检测、老人管理、设备管理、告警管理、用户管理数据集670张跌倒场景图片 YOLO格式标注部署方式本地运行 / 服务器部署二、项目目录结构elderly_monitor_system/ ├── app.py # Flask主程序 ├── config.py # 配置文件 ├── requirements.txt # 依赖列表 ├── models/ # YOLO模型相关 │ ├── yolov5s.pt # 预训练权重 │ └── detect.py # 跌倒检测推理代码 ├── static/ # 前端静态资源 │ ├── css/ │ ├── js/ │ └── images/ ├── templates/ # 前端页面 │ ├── index.html # 首页 │ ├── login.html # 登录页 │ ├── alarm_detail.html # 告警详情页 │ └── device_detail.html # 设备详情页 ├── data/ # 数据集 │ ├── images/ # 670张跌倒图片 │ └── labels/ # YOLO格式标注文件 ├── uploads/ # 上传的图片/视频 └── instance/ # SQLite数据库文件三、环境依赖安装pipinstallflask flask_sqlalchemy opencv-python torch torchvision四、核心代码实现1. Flask主程序app.pyfromflaskimportFlask,render_template,request,redirect,url_for,flashfromflask_sqlalchemyimportSQLAlchemyimportosimportcv2importtorchfromdatetimeimportdatetime appFlask(__name__)app.config[SECRET_KEY]your_secret_keyapp.config[SQLALCHEMY_DATABASE_URI]sqlite:///instance/elderly.dbapp.config[UPLOAD_FOLDER]uploadsos.makedirs(app.config[UPLOAD_FOLDER],exist_okTrue)dbSQLAlchemy(app)# -------------------- 数据库模型 --------------------classUser(db.Model):iddb.Column(db.Integer,primary_keyTrue)usernamedb.Column(db.String(50),uniqueTrue,nullableFalse)passworddb.Column(db.String(100),nullableFalse)classElderly(db.Model):iddb.Column(db.Integer,primary_keyTrue)namedb.Column(db.String(50),nullableFalse)roomdb.Column(db.String(20))device_iddb.Column(db.Integer,db.ForeignKey(device.id))classDevice(db.Model):iddb.Column(db.Integer,primary_keyTrue)namedb.Column(db.String(50))locationdb.Column(db.String(100))statusdb.Column(db.String(20),defaultactive)elderly_iddb.Column(db.Integer,db.ForeignKey(elderly.id))classAlarm(db.Model):iddb.Column(db.Integer,primary_keyTrue)typedb.Column(db.String(50))timedb.Column(db.DateTime,defaultdatetime.utcnow)statusdb.Column(db.String(20),defaultunhandled)elderly_iddb.Column(db.Integer,db.ForeignKey(elderly.id))device_iddb.Column(db.Integer,db.ForeignKey(device.id))image_pathdb.Column(db.String(200))# -------------------- YOLO跌倒检测模型 --------------------modeltorch.hub.load(ultralytics/yolov5,custom,pathmodels/yolov5s.pt,force_reloadTrue)defdetect_fall(image_path):imgcv2.imread(image_path)resultsmodel(img)detectionsresults.pandas().xyxy[0]fall_detectedFalsefor_,rowindetections.iterrows():ifrow[name]fallandrow[confidence]0.4:fall_detectedTruecv2.rectangle(img,(int(row[xmin]),int(row[ymin])),(int(row[xmax]),int(row[ymax])),(0,0,255),2)cv2.putText(img,f跌倒{row[confidence]:.2f},(int(row[xmin]),int(row[ymin])-10),cv2.FONT_HERSHEY_SIMPLEX,0.5,(0,0,255),2)output_pathos.path.join(static/images,fall_result.jpg)cv2.imwrite(output_path,img)returnfall_detected,output_path# -------------------- 路由 --------------------app.route(/)defindex():returnrender_template(index.html)app.route(/login,methods[GET,POST])deflogin():ifrequest.methodPOST:usernamerequest.form[username]passwordrequest.form[password]userUser.query.filter_by(usernameusername,passwordpassword).first()ifuser:returnredirect(url_for(dashboard))flash(用户名或密码错误)returnrender_template(login.html)app.route(/dashboard)defdashboard():returnrender_template(dashboard.html)app.route(/alarm/int:alarm_id)defalarm_detail(alarm_id):alarmAlarm.query.get_or_404(alarm_id)returnrender_template(alarm_detail.html,alarmalarm)app.route(/upload_image,methods[POST])defupload_image():iffilenotinrequest.files:returnredirect(request.url)filerequest.files[file]iffile.filename:returnredirect(request.url)iffile:filenameos.path.join(app.config[UPLOAD_FOLDER],file.filename)file.save(filename)fall_detected,result_imgdetect_fall(filename)iffall_detected:new_alarmAlarm(typefall_detected,image_pathresult_img)db.session.add(new_alarm)db.session.commit()returnrender_template(upload_result.html,fallfall_detected,img_pathresult_img)if__name____main__:withapp.app_context():db.create_all()app.run(host0.0.0.0,port5000,debugTrue)2. 跌倒检测推理models/detect.pyimportcv2importtorchdefload_model(weights_path):modeltorch.hub.load(ultralytics/yolov5,custom,pathweights_path,force_reloadTrue)returnmodeldefdetect_and_draw(model,image_path,output_path):imgcv2.imread(image_path)resultsmodel(img)detectionsresults.pandas().xyxy[0]fall_detectedFalsefor_,rowindetections.iterrows():ifrow[name]fallandrow[confidence]0.4:fall_detectedTruecv2.rectangle(img,(int(row[xmin]),int(row[ymin])),(int(row[xmax]),int(row[ymax])),(0,0,255),2)cv2.putText(img,f跌倒{row[confidence]:.2f},(int(row[xmin]),int(row[ymin])-10),cv2.FONT_HERSHEY_SIMPLEX,0.5,(0,0,255),2)cv2.imwrite(output_path,img)returnfall_detected五、数据集说明数据规模670张图片包含不同场景、角度的跌倒/非跌倒画面标注格式YOLO.txt格式每行格式为class_id x_center y_center width height类别定义0: fall跌倒目录结构data/ ├── images/ # 670张图片.jpg/.png └── labels/ # 对应标注文件.txt六、部署运行步骤环境准备安装 Python 3.8 和依赖库初始化数据库运行一次app.py自动创建instance/elderly.db模型准备将训练好的yolov5s.pt放入models/目录启动服务python app.py访问系统浏览器打开http://localhost:5000即可登录使用七、核心功能扩展说明实时监控可接入摄像头流调用detect_and_draw实现实时跌倒检测告警推送可接入短信/微信API跌倒告警时自动推送通知给家属视频检测在upload_image基础上扩展视频流逐帧检测功能误报管理系统支持标记告警为「已处理/误报」用于后续模型优化八、交付内容说明完整源码上述代码前端页面templates/目录下的HTML文件运行文档包含环境搭建、数据库初始化、部署步骤的详细说明数据集670张跌倒图片及对应YOLO标注文件