Methods
Note: Examples in this guide assume you have already configured FaceRecognizerConfig with model specifications. See Configuration Guide for complete setup details.
Methods Overview
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
Optional[FaceRecognitionResult]- Face recognition result for the enrolled face, orNoneif no face was detected. See FaceRecognitionResult Reference
How It Works
Detects all faces in the image
Selects the largest face (by bounding box area)
Extracts face embedding
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
attributesvalue 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
Processes all images through detection → embedding pipeline
For each image, selects largest face
Stores each embedding with corresponding attributes
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 justlistMatch lengths: Ensure
framesandattributeshave same lengthMultiple 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
InferenceResults- Object with.facesproperty containing list ofFaceRecognitionResultobjects. See FaceRecognitionResult Reference for properties. InferenceResults objects support standard PySDK methods likeimage_overlay(),results, etc. See InferenceResults documentation
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 likeimage_overlay(),results, etc. See InferenceResults documentation for complete API reference.
How It Works
Accepts iterator/generator yielding frames
Processes frames through detection → embedding → matching pipeline
Yields results as they're ready (streaming)
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 loopPipeline 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 automaticallyFor images: Use
iter(image_list)to convert list to iteratorCustom needs: Define your own generator for preprocessing or frame skipping
FPS control: Use
fps=Nparameter invideo_source()to control processing rateTracking: For persistent face IDs across frames, consider using FaceTracker instead
Last updated
Was this helpful?

