项目运行
需要先安装Python的相关依赖:pymysql,Django==3.2.8,pillow 使用pip install 安装
第一步:创建数据库
第二步:执行SQL语句,.sql文件,运行该文件中的SQL语句
第三步:修改源代码中的settings.py文件,改成自己的mysql数据库用户名和密码
第四步:运行命令:python manage.py runserver 8000
第五步:打开浏览器查看http://127.0.0.1:8000
毕设帮助,指导,本源码分享(见文末)
系统介绍:
本系统是一款基于Python编程语言和OpenCV图像处理库开发的疲劳检测系统,旨在通过分析人脸图像来判断测试者的疲劳程度。系统通过检测测试者的眼睛闭合程度、眨眼频次以及面部表情来表征测试者的疲劳程度,并通过Mysql数据库存储和管理图像识别数据。
整体功能包含:
- 用户登录与注册
- 实时人脸图像捕捉与分析
- 疲劳程度评估与预警
- 数据存储与管理
前台模块:
- 登录/注册页面:用户可以进行系统登录或注册新账户
- 图片识别界面:用户可以通过摄像头进行实时人脸图像捕捉
- 照片分析界面:展示用户眼睛状态、打哈欠占比等疲劳分析数据
后台模块:
- 照片管理界面:管理用户上传的图像内容,包括删除异常图片
- 用户管理界面:修改用户信息,新增用户等操作
功能截图:
代码实现:
def register(request):
"""
注册账号
:return:
"""
try:
name = request.POST.get('username')
passwd = request.POST.get('password')
phone = request.POST.get('phone')
user = User.objects.filter(name=name)
if user:
return JsonResponse({'message': '用户已存在,请直接登录'}, status=403)
User.objects.create(
name=name,
password=passwd,
phone=phone,
role=2,
description=''
)
response_data = {'message': '注册成功'}
return JsonResponse(response_data)
except Exception as e:
print(e)
return JsonResponse({'message': '注册失败'}, status=401)
def password(request):
username = request.session['username']
role = int(request.session['role'])
user_id = request.session['user_id']
return render(request, 'modify_password.html', locals())
def get_user(request):
"""
获取用户列表信息 | 模糊查询
:param request:
:return:
"""
keyword = request.GET.get('name')
page = request.GET.get("page", '')
limit = request.GET.get("limit", '')
role_id = request.GET.get('position', '')
response_data = {}
response_data['code'] = 0
response_data['msg'] = ''
data = []
if keyword is None:
results_obj = User.objects.all()
else:
results_obj = User.objects.filter(name__contains=keyword).all()
paginator = Paginator(results_obj, limit)
results = paginator.page(page)
if results:
for user in results:
record = {
"id": user.id,
"name": user.name,
"password": user.password,
"phone": user.phone,
"role": user.role,
'create_time': user.create_time.strftime('%Y-%m-%d %H:%m:%S'),
"desc": user.description,
}
data.append(record)
response_data['count'] = len(results_obj)
response_data['data'] = data
return JsonResponse(response_data)
def user(request):
"""
跳转用户页面
"""
username = request.session['username']
role = int(request.session['role'])
user_id = request.session['user_id']
return render(request, 'user.html', locals())
def login_check(request):
"""
登录校验
"""
response_data = {}
name = request.POST.get('username')
password = request.POST.get('password')
user = User.objects.filter(name=name, password=password).first()
info = {}
if user:
# 将用户名存入session中
request.session["username"] = user.name
request.session["role"] = user.role
request.session["user_id"] = user.id
response_data['message'] = '登录成功'
return JsonResponse(response_data, status=201)
else:
return JsonResponse({'message': '用户名或者密码不正确'}, status=401)
def edit_user(request):
"""
修改用户
"""
response_data = {}
user_id = request.POST.get('id')
username = request.POST.get('username')
phone = request.POST.get('phone')
desc = request.POST.get('desc')
User.objects.filter(id=user_id).update(
name=username,
desc=desc,
phone=phone)
response_data['msg'] = 'success'
return JsonResponse(response_data, status=201)
def del_user(request):
"""
删除用户
"""
user_id = request.POST.get('id')
result = User.objects.filter(id=user_id).first()
try:
if not result:
response_data = {'error': '删除失败!', 'message': '找不到id为%s' % user_id}
return JsonResponse(response_data, status=403)
result.delete()
response_data = {'message': '删除成功!'}
return JsonResponse(response_data, status=201)
except Exception as e:
response_data = {'message': '删除失败!'}
return JsonResponse(response_data, status=403)
def change_password(request):
"""
修改密码
"""
old_pwd = request.POST.get('password1')
username = request.session["username"]
user_obj = User.objects.filter(name=username).first()
if user_obj.password == old_pwd:
User.objects.filter(name=username).update(password=request.POST.get('password2'))
return JsonResponse({'msg': '修改成功!', 'error': 0})
else:
return JsonResponse({'msg': '旧密码不正确,请重新输入', 'error': 403})
论文参考:
源码获取:
源码下载