人脸
This commit is contained in:
		@ -234,3 +234,36 @@ async def delete_face(
 | 
			
		||||
        raise Exception(f"删除人脸记录失败:{str(e)}") from e
 | 
			
		||||
    finally:
 | 
			
		||||
        db.close_connection(conn, cursor)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def get_all_face_name_with_eigenvalue() -> dict:
 | 
			
		||||
    """
 | 
			
		||||
    获取所有人脸的名称及其对应的特征值,组成字典返回
 | 
			
		||||
    key: 人脸名称(name)
 | 
			
		||||
    value: 人脸特征值(eigenvalue)
 | 
			
		||||
    注:过滤掉name为None的记录,避免字典key为None的情况
 | 
			
		||||
    """
 | 
			
		||||
    conn = None
 | 
			
		||||
    cursor = None
 | 
			
		||||
    try:
 | 
			
		||||
        conn = db.get_connection()
 | 
			
		||||
        cursor = conn.cursor(dictionary=True)
 | 
			
		||||
 | 
			
		||||
        # 只查询需要的字段,提高效率
 | 
			
		||||
        query = "SELECT name, eigenvalue FROM face WHERE name IS NOT NULL"
 | 
			
		||||
        cursor.execute(query)
 | 
			
		||||
        faces = cursor.fetchall()
 | 
			
		||||
 | 
			
		||||
        # 构建name到eigenvalue的映射字典
 | 
			
		||||
        face_dict = {
 | 
			
		||||
            face["name"]: face["eigenvalue"]
 | 
			
		||||
            for face in faces
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return face_dict
 | 
			
		||||
 | 
			
		||||
    except MySQLError as e:
 | 
			
		||||
        raise Exception(f"获取人脸名称与特征值失败:{str(e)}") from e
 | 
			
		||||
    finally:
 | 
			
		||||
        # 确保资源释放
 | 
			
		||||
        db.close_connection(conn, cursor)
 | 
			
		||||
		Reference in New Issue
	
	Block a user