diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 1fb3389..b64b968 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -5,8 +5,21 @@ + - + + + + + + + + + + + + + - + - + diff --git a/app.py b/app.py index 75ce246..ff8b03c 100644 --- a/app.py +++ b/app.py @@ -1,16 +1,19 @@ -from flask import Flask, render_template +from flask import Flask, render_template, request, redirect, url_for from flask_socketio import SocketIO, emit import sqlite3 +import os import eventlet +import face_recognition app = Flask(__name__) +app.config['UPLOAD_FOLDER'] = './static/db_image' # 设置文件上传路径 socketio = SocketIO(app, async_mode='eventlet') # 从数据库中获取匹配日志记录 def get_match_logs(db_name="face_database.db"): conn = sqlite3.connect(db_name) c = conn.cursor() - c.execute("SELECT name, identity,image_path,match_time FROM match_logs") # 去掉了 image_path + c.execute("SELECT name, identity, image_path, match_time FROM match_logs") logs = c.fetchall() conn.close() return logs @@ -21,6 +24,81 @@ def index(): logs = get_match_logs() return render_template('index.html', logs=logs) +# 人员信息页面,展示人员信息并进行CRUD操作 +@app.route('/info_person', methods=['GET', 'POST']) +def info_person(): + conn = sqlite3.connect('face_database.db') + c = conn.cursor() + + if request.method == 'POST': + # 添加新人员 + if 'add' in request.form: + name = request.form['name'] + identity = request.form['identity'] + image = request.files['image_path'] + + # 保存上传的图片并生成编码 + if image: + image_path = os.path.join(app.config['UPLOAD_FOLDER'], image.filename) + image.save(image_path) + + # 使用face_recognition生成面部编码 + loaded_image = face_recognition.load_image_file(image_path) + face_encodings = face_recognition.face_encodings(loaded_image) + + if face_encodings: + encoding = ','.join(map(str, face_encodings[0])) # 将编码转换为字符串存储 + image_path = "db_image/"+image.filename # 仅保存文件名以便后续使用 + else: + return "No face detected in the uploaded image." + else: + image_path = "" + encoding = "" + + c.execute("INSERT INTO faces (name, identity, image_path, encoding) VALUES (?, ?, ?, ?)", + (name, identity, image_path, encoding)) + + # 更新人员信息 + elif 'update' in request.form: + id = request.form['id'] + name = request.form['name'] + identity = request.form['identity'] + image = request.files.get('image_path') + + if image: + image_path = os.path.join(app.config['UPLOAD_FOLDER'], image.filename) + image.save(image_path) + + # 使用face_recognition生成新的面部编码 + loaded_image = face_recognition.load_image_file(image_path) + face_encodings = face_recognition.face_encodings(loaded_image) + + if face_encodings: + encoding = ','.join(map(str, face_encodings[0])) # 将编码转换为字符串存储 + image_path = image.filename # 仅保存文件名 + else: + return "No face detected in the uploaded image." + else: + image_path = request.form['current_image_path'] # 使用当前的图片路径 + encoding = request.form['encoding'] # 使用现有的编码 + + c.execute("UPDATE faces SET name=?, identity=?, image_path=?, encoding=? WHERE id=?", + (name, identity, image_path, encoding, id)) + + # 删除人员信息 + elif 'delete' in request.form: + id = request.form['id'] + c.execute("DELETE FROM faces WHERE id=?", (id,)) + + conn.commit() + + # 获取所有人员记录 + c.execute("SELECT * FROM faces") + persons = c.fetchall() + conn.close() + + return render_template('info_person.html', persons=persons) + # 处理 WebSocket 连接 @socketio.on('connect') def handle_connect(): diff --git a/captured_faces/face_1.jpg b/captured_faces/face_1.jpg index 17203d7..15e6cca 100644 Binary files a/captured_faces/face_1.jpg and b/captured_faces/face_1.jpg differ diff --git a/captured_faces/face_10.jpg b/captured_faces/face_10.jpg index c753b82..6f707a1 100644 Binary files a/captured_faces/face_10.jpg and b/captured_faces/face_10.jpg differ diff --git a/captured_faces/face_2.jpg b/captured_faces/face_2.jpg index d4d9a11..fbe4b4f 100644 Binary files a/captured_faces/face_2.jpg and b/captured_faces/face_2.jpg differ diff --git a/captured_faces/face_3.jpg b/captured_faces/face_3.jpg index 35afc36..602ce65 100644 Binary files a/captured_faces/face_3.jpg and b/captured_faces/face_3.jpg differ diff --git a/captured_faces/face_4.jpg b/captured_faces/face_4.jpg index e76b554..21a5ce3 100644 Binary files a/captured_faces/face_4.jpg and b/captured_faces/face_4.jpg differ diff --git a/captured_faces/face_5.jpg b/captured_faces/face_5.jpg index b07a1b7..2dafe81 100644 Binary files a/captured_faces/face_5.jpg and b/captured_faces/face_5.jpg differ diff --git a/captured_faces/face_6.jpg b/captured_faces/face_6.jpg index 07f9673..4402fc5 100644 Binary files a/captured_faces/face_6.jpg and b/captured_faces/face_6.jpg differ diff --git a/captured_faces/face_7.jpg b/captured_faces/face_7.jpg index 84ee3c1..f5c8812 100644 Binary files a/captured_faces/face_7.jpg and b/captured_faces/face_7.jpg differ diff --git a/captured_faces/face_8.jpg b/captured_faces/face_8.jpg index 7acc83b..aaf2ce1 100644 Binary files a/captured_faces/face_8.jpg and b/captured_faces/face_8.jpg differ diff --git a/captured_faces/face_9.jpg b/captured_faces/face_9.jpg index 6175c8c..727e96e 100644 Binary files a/captured_faces/face_9.jpg and b/captured_faces/face_9.jpg differ diff --git a/face_database.db b/face_database.db deleted file mode 100644 index 8bff6c2..0000000 Binary files a/face_database.db and /dev/null differ diff --git a/match_log.txt b/match_log.txt deleted file mode 100644 index 38b7fba..0000000 --- a/match_log.txt +++ /dev/null @@ -1 +0,0 @@ -,,db_image\test1.jpg diff --git a/static/db_image/28b9113283b332eccff5bcae295a17e8_origin(1).jpg b/static/db_image/28b9113283b332eccff5bcae295a17e8_origin(1).jpg new file mode 100644 index 0000000..90f9846 Binary files /dev/null and b/static/db_image/28b9113283b332eccff5bcae295a17e8_origin(1).jpg differ diff --git a/templates/index.html b/templates/index.html index 1063f4b..c9a59b2 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,22 +1,45 @@ - Face Match Logs - + 后台管理系统 + + + + +
+

进入记录

+ + + + + + + + + + + + +
姓名身份进入时间照片
+
+ + - - -

进入记录

- - - - - - - - - - - - -
姓名身份进入时间照片
diff --git a/templates/info_person.html b/templates/info_person.html new file mode 100644 index 0000000..2f72bb5 --- /dev/null +++ b/templates/info_person.html @@ -0,0 +1,232 @@ + + + + + + 人员信息管理 + + + + + +
+

人员信息管理

+ + + + + + + + + + + {% for person in persons %} + + + + + + + + {% endfor %} + +
姓名身份照片操作
{{ person[1] }}{{ person[2] }}Photo of {{ person[1] }} +
+ + + + + + + +
+
+ + +
+
+ +
+

添加新人员

+
+
+ + +
+
+ + +
+
+ + + +
+ +
+
+
+ + + +