毕设项目:基于Qt、PYTHON智能校园防御系统应用程序,实现了摄像头数据采集、人脸识别、口罩识别、 数据统计等功能

完整项目地址:https://download.csdn.net/download/lijunhcn/88453470

项目结构

环境选型
  1. 语言:Python
  2. 操作系统:Windows
  3. 数据库:MySQL
  4. 窗口界面:PyQT
  5. API接口:百度AI接口,用以实现人脸登陆与注册
远程MySQL表结构

远程表结构sql脚本
DROP TABLE IF EXISTS `access_record_table`;CREATE TABLE `access_record_table` (record_id int(11) NOT NULL AUTO_INCREMENTCOMMENT '主键',has_mask enum('0','1') NOT NULL DEFAULT '0' COMMENT '是否佩戴口罩',access_time timestamp DEFAULT CURRENT_TIMESTAMP COMMENT '记录时间',place_id int(11) UNSIGNED NOT NULL DEFAULT '00000' COMMENT '设备id',stu_id int(1) int(11)UNSIGNED NOT NULL DEFAULT '00000' COMMENT '学生id',PRIMARY KEY (record_id)) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;DROP TABLE IF EXISTS `place_table`;CREATE TABLE `place_table` (place_id int,place_name varchar(32) DEFAULT NULL COMMENT '地点名字',place_time timestamp DEFAULT CURRENT_TIMESTAMP COMMENT '记录时间',foreign key(place_id) references access_record_table(place_id) on delete cascade on update cascade) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;DROP TABLE IF EXISTS `stu_table`;CREATE TABLE `stu_table` (stu_id int,stu_name varchar(32) DEFAULT NULL COMMENT '学生名字',stu_status enum('0','1','2') NOT NULL DEFAULT '0' COMMENT '学生状态',stu_times timestamp DEFAULT CURRENT_TIMESTAMP COMMENT '记录时间',foreign key(stu_id) references access_record_table(stu_id) on delete cascade on update cascade) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;DROP TABLE IF EXISTS `usr_table`;CREATE TABLE `usr_table` (stu_id int(11) NOT NULL AUTO_INCREMENTCOMMENT '主键',usr_name varchar(32) DEFAULT NULL COMMENT '用户名称',usr_pic varchar(32) DEFAULT NULL COMMENT '用户图片名称',usr_times timestamp DEFAULT CURRENT_TIMESTAMP COMMENT '记录时间',PRIMARY KEY (stu_id)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
项目背景

智能校园防御软件是实现了一款基于摄像头数据采集、人脸识别、口罩识别、 数据统计的预警系统,该种防御系统能够通过人脸识别进行管理员登录打卡,通过安装在教室内的固定摄像头,实时采集教室内上课同学的图像,判断是否有带口罩,从而在监控屏幕中予以标记提示警卫人员。采用 OpenCV/爬虫数据采集、利用 Numpy、Pandas 及特征工程、模型聚合进行数据预处理、CNN 模型训练框架。

部分源码:

# *coding:utf-8 *from Global import CONFIGimport pymysqlclass CDbOpt:def __init__(self):"""MySql操纵类函数的相关初始化数值"""self.conn_mysql = pymysql.Connect(database=CONFIG["@mysql_opt"]["mysql_db"],user=CONFIG["@mysql_opt"]["mysql_user"],password=CONFIG["@mysql_opt"]["mysql_pwd"],host=CONFIG["@mysql_opt"]["mysql_host"],port=CONFIG["@mysql_opt"]["mysql_port"],charset=CONFIG["@mysql_opt"]["mysql_charset"],)def __del__(self):"""析构函数: 关闭Sql连接"""self.conn_mysql.close()def Db_Selete(self, *args, **kwargs):# 获取数据字段# 整理出sql# 调用dbtable = args[0]where_fields = ''data = kwargs.get('data')where_list = data.get('where_list')select_list = data.get('select_list')if where_list != None:del data['where_list']if select_list != None:del data['select_list']for k, v in data.items():if k in where_list:if where_fields == '':where_fields += f"{k}='{v}'"else:where_fields += f"and {k}='{v}'"fields = ','.join(select_list)cursor = self.conn_mysql.cursor()sql = f"""select {fields} from {table} where {where_fields}"""cursor.execute(sql)result = cursor.fetchall()return resultdef Db_SELECT_SQL(self, sql):# 获取数据字段# 整理出sql# 调用dbcursor = self.conn_mysql.cursor()cursor.execute(sql)result = cursor.fetchall()return resultdef Db_Update_SQL(self, sql):# 调用sqlcursor = self.conn_mysql.cursor()try:cursor.execute(sql)self.conn_mysql.commit()return Trueexcept Exception as e:print(e)self.conn_mysql.rollback()return Falsedef Db_Update(self, *args, **kwargs):table = args[0]fields = ''where_fields = ''data = kwargs.get('data')where_list = data.get('where_list')select_list = data.get('select_list')if where_list != None:del data['where_list']if select_list != None:del data['select_list']for k, v in data.items():if k in where_list:if where_fields == '':where_fields += f"{k}='{v}'"else:where_fields += f"and {k}='{v}'"else:if fields == '':fields += f"{k}='{v}'"else:fields += f", {k}='{v}'"# 调用sqlcursor = self.conn_mysql.cursor()sql = f"""update {table} set {fields} where {where_fields}"""try:cursor.execute(sql)self.conn_mysql.commit()except Exception as e:print(e)self.conn_mysql.rollback()def Db_Insert(self, *args, **kwargs):table = args[0]fields = ''where_fields = ''data = kwargs.get('data')where_list = data.get('where_list')select_list = data.get('select_list')if where_list != None:del data['where_list']if select_list != None:del data['select_list']num = 0for k, v in data.items():if num == 0:where_fields += f"{k}"fields += f"'{v}'"else:where_fields += f", {k}"fields += f", '{v}'"num += 1cursor = self.conn_mysql.cursor()sql = f"""insert into {table} ({where_fields}) values({fields})"""try:cursor.execute(sql)self.conn_mysql.commit()return Trueexcept Exception as e:print(e)self.conn_mysql.rollback()return Falsedef Db_Delete(self, *args, **kwargs):table = args[0]fields = ''where_fields = ''data = kwargs.get('data')where_list = data.get('where_list')select_list = data.get('select_list')if where_list != None:del data['where_list']if select_list != None:del data['select_list']for k, v in data.items():if fields == '':fields += f"{k}='{v}'"else:fields += f", {k}='{v}'"if k in where_list:if where_fields == '':where_fields += f"{k}='{v}'"else:where_fields += f"and {k}='{v}'"cursor = self.conn_mysql.cursor()sql = f"""delete from {table} where {where_fields}"""try:cursor.execute(sql)self.conn_mysql.commit()except Exception as e:print(e)self.conn_mysql.rollback()