Methods

Note: Examples in this guide assume you have already configured FaceRecognizerConfig with model specifications. See Configuration Guide for complete setup details.

Methods Overview

Method
Purpose
Input
Best For

enroll_image()

Add single face to database

One image, one name

Interactive enrollment

enroll_batch()

Add multiple faces to database

Image iterator, names

Bulk enrollment

predict()

Recognize faces in one image

One image

Single photo processing

predict_batch()

Recognize faces in multiple images

Image iterator

Video/batch processing

Performance tip: Use _batch() methods for multiple items - they provide ~2-3x speedup through pipeline parallelism.

FaceRecognitionResult

FaceRecognitionResult objects represent detected faces with their properties. Returned directly by enrollment methods and contained in prediction results.

Key properties: attributes, similarity_score, bbox, embeddings, images

See FaceRecognitionResult Reference for complete property list and usage examples.


enroll_image()

Enroll a single person's face from one image.

Signature

Parameters

  • frame - Image as numpy array or file path (str)

  • attributes - Person identifier (typically a name string, but can be any Python dictionary). The dictionary structure must be the same for all enrollments

Returns

How It Works

  1. Detects all faces in the image

  2. Selects the largest face (by bounding box area)

  3. Extracts face embedding

  4. Stores embedding in database with the provided attributes

Examples

Enroll from file path:

Enroll from numpy array:

Enroll multiple photos of same person:

Best Practices

  • Use clear, frontal face images for best enrollment quality

  • One person per image - If multiple faces present, largest is selected

  • Enroll multiple photos per person from different angles/lighting

  • Consistent naming - Use the same attributes value for the same person


enroll_batch()

Enroll multiple faces from multiple images efficiently.

Signature

Parameters

  • frames - Iterable of images (file paths or numpy arrays)

  • attributes - Iterable of person identifiers (must match frames order)

Returns

  • List[FaceRecognitionResult] - List of face recognition results for enrolled faces (frames with no detected faces are skipped). See FaceRecognitionResult Reference

How It Works

  1. Processes all images through detection → embedding pipeline

  2. For each image, selects largest face

  3. Stores each embedding with corresponding attributes

  4. Pipeline parallelism makes this faster than calling enroll_image() repeatedly

Examples

Enroll multiple people:

Enroll multiple photos of same person:

Bulk enrollment from directory:

Best Practices

  • Prefer using iterators: iter(list) not just list

  • Match lengths: Ensure frames and attributes have same length

  • Multiple photos per person: Improves accuracy across different conditions

  • Use batch for 3+ enrollments: Performance benefit over individual calls


predict()

Recognize all faces in a single image.

Signature

Parameters

  • frame - Image as numpy array or file path (str)

Returns

Examples

Basic recognition:

Access all face properties:

Pretty print (uses __str__()):

Example output:

Filter by confidence:

Access cropped face images:

Note: The images list contains aligned and cropped face images (typically 112×112) that were used for embedding extraction. These are useful for:

  • Visual verification of detected faces

  • Creating face galleries or thumbnails

  • Quality assurance and debugging

  • Building custom datasets

When to Use

  • Processing individual photos

  • Simple recognition tasks

  • Testing and debugging

  • Real-time single-frame analysis


predict_batch()

Recognize faces across multiple images or video efficiently using pipeline parallelism.

Signature

Parameters

  • frames - Iterable of images (file paths, numpy arrays) or video frames from generator

Returns

  • Iterator[InferenceResults] - Iterator yielding results for each input frame. InferenceResults objects support standard PySDK methods like image_overlay(), results, etc. See InferenceResults documentationarrow-up-right for complete API reference.

How It Works

  1. Accepts iterator/generator yielding frames

  2. Processes frames through detection → embedding → matching pipeline

  3. Yields results as they're ready (streaming)

  4. Pipeline parallelism provides ~2-3x speedup over calling predict() in a loop

Examples

Example 1: Multiple image files

Example 2: Video streams (recommended)

For video files, webcams, or RTSP streams, use degirum_tools video helpers:

Video source options:

  • Webcam: open_video_stream(0) - Index 0, 1, 2, etc.

  • Video file: open_video_stream('video.mp4')

  • RTSP stream: open_video_stream('rtsp://192.168.1.100/stream')

  • FPS control: video_source(stream, fps=5) - Process N frames/sec

Example 3: Custom frame generator

Define your own generator for custom preprocessing or frame selection:

Example 4: Batch directory processing

Performance Benefits

  • ~2-3x faster than calling predict() in a loop

  • Pipeline stages run in parallel (detection, embedding, matching)

  • Ideal for video streams and high-throughput batch processing

  • Streaming results (memory efficient)

Best Practices

  • For video: Use degirum_tools.video_source() - handles webcam, files, RTSP automatically

  • For images: Use iter(image_list) to convert list to iterator

  • Custom needs: Define your own generator for preprocessing or frame skipping

  • FPS control: Use fps=N parameter in video_source() to control processing rate

  • Tracking: For persistent face IDs across frames, consider using FaceTracker instead


Last updated

Was this helpful?