Introduce vision area based hashing

This commit is contained in:
henryruhs
2025-06-18 00:43:53 +02:00
parent 93756d1295
commit fc501754cd

View File

@@ -17,29 +17,24 @@ def get_face_store() -> FaceStore:
def get_static_faces(vision_frame : VisionFrame) -> Optional[List[Face]]:
frame_hash = create_frame_hash(vision_frame)
if frame_hash in FACE_STORE['static_faces']:
return FACE_STORE['static_faces'][frame_hash]
vision_area = crop_vision_area(vision_frame)
vision_hash = create_hash(vision_area.tobytes())
if vision_hash in FACE_STORE['static_faces']:
return FACE_STORE['static_faces'][vision_hash]
return None
def set_static_faces(vision_frame : VisionFrame, faces : List[Face]) -> None:
frame_hash = create_frame_hash(vision_frame)
if frame_hash:
FACE_STORE['static_faces'][frame_hash] = faces
vision_area = crop_vision_area(vision_frame)
vision_hash = create_hash(vision_area.tobytes())
if vision_hash:
FACE_STORE['static_faces'][vision_hash] = faces
def clear_static_faces() -> None:
FACE_STORE['static_faces'].clear()
def create_frame_hash(vision_frame : VisionFrame) -> Optional[str]:
if numpy.any(vision_frame):
frame_hash = create_hash(vision_frame.tobytes())
return frame_hash
return None
def get_reference_faces() -> Optional[FaceSet]:
if FACE_STORE['reference_faces']:
return FACE_STORE['reference_faces']
@@ -54,3 +49,10 @@ def append_reference_face(name : str, face : Face) -> None:
def clear_reference_faces() -> None:
FACE_STORE['reference_faces'].clear()
def crop_vision_area(vision_frame : VisionFrame) -> VisionFrame:
height, width = vision_frame.shape[:2]
center_y, center_x = height // 2, width // 2
vision_area = vision_frame[center_y - 16 : center_y + 16, center_x - 16 : center_x + 16]
return vision_area