Introduce vision area based hashing
This commit is contained in:
@@ -17,29 +17,24 @@ def get_face_store() -> FaceStore:
|
|||||||
|
|
||||||
|
|
||||||
def get_static_faces(vision_frame : VisionFrame) -> Optional[List[Face]]:
|
def get_static_faces(vision_frame : VisionFrame) -> Optional[List[Face]]:
|
||||||
frame_hash = create_frame_hash(vision_frame)
|
vision_area = crop_vision_area(vision_frame)
|
||||||
if frame_hash in FACE_STORE['static_faces']:
|
vision_hash = create_hash(vision_area.tobytes())
|
||||||
return FACE_STORE['static_faces'][frame_hash]
|
if vision_hash in FACE_STORE['static_faces']:
|
||||||
|
return FACE_STORE['static_faces'][vision_hash]
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def set_static_faces(vision_frame : VisionFrame, faces : List[Face]) -> None:
|
def set_static_faces(vision_frame : VisionFrame, faces : List[Face]) -> None:
|
||||||
frame_hash = create_frame_hash(vision_frame)
|
vision_area = crop_vision_area(vision_frame)
|
||||||
if frame_hash:
|
vision_hash = create_hash(vision_area.tobytes())
|
||||||
FACE_STORE['static_faces'][frame_hash] = faces
|
if vision_hash:
|
||||||
|
FACE_STORE['static_faces'][vision_hash] = faces
|
||||||
|
|
||||||
|
|
||||||
def clear_static_faces() -> None:
|
def clear_static_faces() -> None:
|
||||||
FACE_STORE['static_faces'].clear()
|
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]:
|
def get_reference_faces() -> Optional[FaceSet]:
|
||||||
if FACE_STORE['reference_faces']:
|
if FACE_STORE['reference_faces']:
|
||||||
return 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:
|
def clear_reference_faces() -> None:
|
||||||
FACE_STORE['reference_faces'].clear()
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user