2 Commits

3 changed files with 24 additions and 4 deletions

11
.gitignore vendored Normal file
View File

@@ -0,0 +1,11 @@
# 运行时生成的数据目录
data/
# Python
__pycache__/
*.pyc
*.pyo
# IDE
.vscode/
.idea/

Binary file not shown.

View File

@@ -537,7 +537,7 @@ class PersonManager:
if save_new_person and confirmed_change:
for person in identified_persons:
if person['is_new'] and len(self.persons) < self.config['max_persons']:
# 保存人脸特征
# 保存人脸特征和人脸图片
x, y, w, h = person['bbox']
face_region = image[y:y+int(h*0.4), x:x+w]
@@ -548,8 +548,8 @@ class PersonManager:
person['person_id'] = person_id
person['name'] = f"Person #{len(self.persons) + 1}"
# 保存到人员库
self.add_new_person_with_encoding(person_id, encoding, person['name'])
# 保存到人员库(包括人脸图片)
self.add_new_person_with_encoding(person_id, encoding, person['name'], face_region)
# 清空缓冲区,更新状态
self.confirmation_buffer = {key: self.confirmation_buffer[key]}
@@ -580,13 +580,14 @@ class PersonManager:
'detection_source': 'yolo'
}
def add_new_person_with_encoding(self, person_id, encoding, name=None):
def add_new_person_with_encoding(self, person_id, encoding, name=None, face_image=None):
"""保存新人员到库(已有 encoding
Args:
person_id: 人员ID
encoding: 特征向量
name: 名称
face_image: 人脸图片(可选,用于保存人脸图片)
Returns:
dict: 人员信息
@@ -594,10 +595,18 @@ class PersonManager:
if name is None:
name = person_id
# 保存人脸图片
face_path = ''
if face_image is not None and face_image.size > 0:
face_path = str(self.faces_dir / f"{person_id}.jpg")
cv2.imwrite(face_path, face_image)
print(f"[PersonManager] Face image saved: {face_path}")
person_data = {
'person_id': person_id,
'name': name,
'face_encoding': encoding.tolist() if isinstance(encoding, np.ndarray) else encoding,
'face_path': face_path,
'first_seen': datetime.datetime.now().isoformat(),
'last_seen': datetime.datetime.now().isoformat(),
'visit_count': 1