Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0ccfcc4903 | |||
| 9e3308db12 |
11
.gitignore
vendored
Normal file
11
.gitignore
vendored
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
# 运行时生成的数据目录
|
||||||
|
data/
|
||||||
|
|
||||||
|
# Python
|
||||||
|
__pycache__/
|
||||||
|
*.pyc
|
||||||
|
*.pyo
|
||||||
|
|
||||||
|
# IDE
|
||||||
|
.vscode/
|
||||||
|
.idea/
|
||||||
BIN
data/events.db
BIN
data/events.db
Binary file not shown.
@@ -537,7 +537,7 @@ class PersonManager:
|
|||||||
if save_new_person and confirmed_change:
|
if save_new_person and confirmed_change:
|
||||||
for person in identified_persons:
|
for person in identified_persons:
|
||||||
if person['is_new'] and len(self.persons) < self.config['max_persons']:
|
if person['is_new'] and len(self.persons) < self.config['max_persons']:
|
||||||
# 保存人脸特征
|
# 保存人脸特征和人脸图片
|
||||||
x, y, w, h = person['bbox']
|
x, y, w, h = person['bbox']
|
||||||
face_region = image[y:y+int(h*0.4), x:x+w]
|
face_region = image[y:y+int(h*0.4), x:x+w]
|
||||||
|
|
||||||
@@ -548,8 +548,8 @@ class PersonManager:
|
|||||||
person['person_id'] = person_id
|
person['person_id'] = person_id
|
||||||
person['name'] = f"Person #{len(self.persons) + 1}"
|
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]}
|
self.confirmation_buffer = {key: self.confirmation_buffer[key]}
|
||||||
@@ -580,13 +580,14 @@ class PersonManager:
|
|||||||
'detection_source': 'yolo'
|
'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)
|
"""保存新人员到库(已有 encoding)
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
person_id: 人员ID
|
person_id: 人员ID
|
||||||
encoding: 特征向量
|
encoding: 特征向量
|
||||||
name: 名称
|
name: 名称
|
||||||
|
face_image: 人脸图片(可选,用于保存人脸图片)
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
dict: 人员信息
|
dict: 人员信息
|
||||||
@@ -594,10 +595,18 @@ class PersonManager:
|
|||||||
if name is None:
|
if name is None:
|
||||||
name = person_id
|
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_data = {
|
||||||
'person_id': person_id,
|
'person_id': person_id,
|
||||||
'name': name,
|
'name': name,
|
||||||
'face_encoding': encoding.tolist() if isinstance(encoding, np.ndarray) else encoding,
|
'face_encoding': encoding.tolist() if isinstance(encoding, np.ndarray) else encoding,
|
||||||
|
'face_path': face_path,
|
||||||
'first_seen': datetime.datetime.now().isoformat(),
|
'first_seen': datetime.datetime.now().isoformat(),
|
||||||
'last_seen': datetime.datetime.now().isoformat(),
|
'last_seen': datetime.datetime.now().isoformat(),
|
||||||
'visit_count': 1
|
'visit_count': 1
|
||||||
|
|||||||
Reference in New Issue
Block a user