File size: 679 Bytes
8fb085a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from typing import Optional, List, Dict
import hashlib

from facefusion.typing import Frame, Face

FACES_CACHE : Dict[str, List[Face]] = {}


def get_faces_cache(frame : Frame) -> Optional[List[Face]]:
	frame_hash = create_frame_hash(frame)
	if frame_hash in FACES_CACHE:
		return FACES_CACHE[frame_hash]
	return None


def set_faces_cache(frame : Frame, faces : List[Face]) -> None:
	frame_hash = create_frame_hash(frame)
	if frame_hash:
		FACES_CACHE[frame_hash] = faces


def clear_faces_cache() -> None:
	global FACES_CACHE

	FACES_CACHE = {}


def create_frame_hash(frame : Frame) -> Optional[str]:
	return hashlib.sha1(frame.tobytes()).hexdigest() if frame.any() else None