Graduation project - based on Qt, PYTHON intelligent campus defense system application, realizing camera data collection, face recognition, mask recognition, data statistics and other functions

Graduation project: Based on Qt and PYTHON intelligent campus defense system application, functions such as camera data collection , face recognition, mask recognition, and data statistics are implemented

Complete project address: https://download.csdn.net/download/lijunhcn/88453470

Project structure

Environment selection
  1. Language: Python
  2. Operating system: Windows
  3. Database: MySQL
  4. Window interface: PyQT
  5. API interface: Baidu AI interface, used to realize face login and registration
Remote MySQL table structure

Remote table structure sql script
DROP TABLE IF EXISTS `access_record_table`;
CREATE TABLE `access_record_table` (
  record_id int(11) NOT NULL AUTO_INCREMENT  COMMENT '主键',
  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_INCREMENT  COMMENT '主键',
  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;
Background of the project

The smart campus defense software implements an early warning system based on camera data collection, face recognition , mask recognition, and data statistics. This defense system can log in and clock in for administrators through face recognition, and through fixed cameras installed in the classroom , collect images of classmates in the classroom in real time to determine whether they are wearing masks, and then mark them on the monitoring screen to remind security personnel. Use OpenCV/crawler data collection, use Numpy, Pandas and feature engineering, model aggregation for data preprocessing, and CNN model training framework.

Part of the source code:

# *coding:utf-8 *
from Global import CONFIG
import pymysql


class 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
        # 调用db
        table = 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 result

    def Db_SELECT_SQL(self, sql):
        # 获取数据字段
        # 整理出sql
        # 调用db
        cursor = self.conn_mysql.cursor()
        cursor.execute(sql)
        result = cursor.fetchall()
        return result

    def Db_Update_SQL(self, sql):
        # 调用sql
        cursor = self.conn_mysql.cursor()
        try:
            cursor.execute(sql)
            self.conn_mysql.commit()
            return True
        except Exception as e:
            print(e)
            self.conn_mysql.rollback()
            return False

    def 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}'"

        # 调用sql
        cursor = 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 = 0
        for k, v in data.items():
            if num == 0:
                where_fields += f"{k}"
                fields += f"'{v}'"
            else:
                where_fields += f", {k}"
                fields += f", '{v}'"
            num += 1

        cursor = self.conn_mysql.cursor()
        sql = f"""insert into {table} ({where_fields}) values({fields})"""
        try:
            cursor.execute(sql)
            self.conn_mysql.commit()
            return True
        except Exception as e:
            print(e)
            self.conn_mysql.rollback()
            return False

    def 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()

Guess you like

Origin blog.csdn.net/lijunhcn/article/details/135177307