Register identities to database for face recognition Args: img (str or np.ndarray or IO[bytes] or list): The exact path to the image, a numpy array in BGR format, a file object that supports at least `.read` and is opened in binary mode, or a base64 encoded i
(
img: Union[str, NDArray[Any], IO[bytes], List[str], List[NDArray[Any]], List[IO[bytes]]],
img_name: Optional[str] = None,
model_name: str = "VGG-Face",
detector_backend: str = "opencv",
enforce_detection: bool = True,
align: bool = True,
l2_normalize: bool = False,
expand_percentage: int = 0,
normalization: str = "base",
anti_spoofing: bool = False,
database_type: str = "postgres",
connection_details: Optional[Union[Dict[str, Any], str]] = None,
connection: Any = None,
)
| 32 | |
| 33 | # pylint: disable=too-many-positional-arguments, no-else-return |
| 34 | def register( |
| 35 | img: Union[str, NDArray[Any], IO[bytes], List[str], List[NDArray[Any]], List[IO[bytes]]], |
| 36 | img_name: Optional[str] = None, |
| 37 | model_name: str = "VGG-Face", |
| 38 | detector_backend: str = "opencv", |
| 39 | enforce_detection: bool = True, |
| 40 | align: bool = True, |
| 41 | l2_normalize: bool = False, |
| 42 | expand_percentage: int = 0, |
| 43 | normalization: str = "base", |
| 44 | anti_spoofing: bool = False, |
| 45 | database_type: str = "postgres", |
| 46 | connection_details: Optional[Union[Dict[str, Any], str]] = None, |
| 47 | connection: Any = None, |
| 48 | ) -> Dict[str, Any]: |
| 49 | """ |
| 50 | Register identities to database for face recognition |
| 51 | Args: |
| 52 | img (str or np.ndarray or IO[bytes] or list): The exact path to the image, a numpy array |
| 53 | in BGR format, a file object that supports at least `.read` and is opened in binary |
| 54 | mode, or a base64 encoded image. If a list is provided, each element should be a string |
| 55 | or numpy array representing an image, and the function will process images in batch. |
| 56 | img_name (optional str): image name to store in db, if not provided then we will try to |
| 57 | extract it from given img. |
| 58 | model_name (str): Model for face recognition. Options: VGG-Face, Facenet, Facenet512, |
| 59 | OpenFace, DeepFace, DeepID, Dlib, ArcFace, SFace and GhostFaceNet (default is VGG-Face). |
| 60 | detector_backend (string): face detector backend. Options: 'opencv', 'retinaface', |
| 61 | 'mtcnn', 'ssd', 'dlib', 'mediapipe', 'yolov8n', 'yolov8m', 'yolov8l', 'yolov11n', |
| 62 | 'yolov11s', 'yolov11m', 'yolov11l', 'yolov12n', 'yolov12s', 'yolov12m', 'yolov12l', |
| 63 | 'centerface' or 'skip' (default is opencv). |
| 64 | enforce_detection (boolean): If no face is detected in an image, raise an exception. |
| 65 | Set to False to avoid the exception for low-resolution images (default is True). |
| 66 | align (bool): Flag to enable face alignment (default is True). |
| 67 | l2_normalize (bool): Flag to enable L2 normalization (unit vector normalization) |
| 68 | expand_percentage (int): expand detected facial area with a percentage (default is 0). |
| 69 | normalization (string): Normalize the input image before feeding it to the model. |
| 70 | Options: base, raw, Facenet, Facenet2018, VGGFace, VGGFace2, ArcFace (default is base). |
| 71 | anti_spoofing (boolean): Flag to enable anti spoofing (default is False). |
| 72 | database_type (str): Type of database to register identities. Options: 'postgres', 'mongo', |
| 73 | 'weaviate', 'neo4j', 'pgvector', 'pinecone' (default is 'postgres'). |
| 74 | connection_details (dict or str): Connection details for the database. |
| 75 | connection (Any): Existing database connection object. If provided, this connection |
| 76 | will be used instead of creating a new one. |
| 77 | |
| 78 | Note: |
| 79 | Instead of providing `connection` or `connection_details`, database connection |
| 80 | information can be supplied via environment variables: |
| 81 | - DEEPFACE_POSTGRES_URI |
| 82 | - DEEPFACE_MONGO_URI |
| 83 | - DEEPFACE_WEAVIATE_URI |
| 84 | - DEEPFACE_NEO4J_URI |
| 85 | - DEEPFACE_PINECONE_API_KEY |
| 86 | Returns: |
| 87 | result (dict): A dictionary containing registration results with following keys. |
| 88 | - inserted (int): Number of embeddings successfully registered to the database. |
| 89 | """ |
| 90 | db_client = __connect_database( |
| 91 | database_type=database_type, |
nothing calls this directly
no test coverage detected