Python API Reference

The affvisionpy module β€” the native SDK wrapped for Python. Methods are snake_case, enum values are lowercase, and metric maps are plain dictionaries. This page documents exactly what the Python binding exposes; anything not listed here (for example the sensor/connector pipeline) is available only in C++.

Module

import affvisionpy as af
AttributeValue / typeDescription
af.__version__str, e.g. "5.4.0.123"full SDK version
af.DEFAULT_PROCESSING_FRAME_RATE30.0default target processing rate (fps)
af.DEFAULT_MAX_NUM_FACES1default maximum tracked faces
af.DEFAULT_MAX_THREAD_POOL_SIZE00 = “use number of CPU cores βˆ’ 1” analysis threads
af.ALL_FEATURES, af.ALL_EXPRESSIONS, af.ALL_EMOTIONS, af.ALL_MEASUREMENTS, af.ALL_FACE_POINTS, af.ALL_QUALITIEScollectionsevery value of the corresponding enum

af.Frame

Wraps one image and its timestamp. pixels is any object exposing the buffer protocol β€” a NumPy array works directly, so an OpenCV image (numpy.ndarray in BGR order) can be passed as-is.

af.Frame(timestamp_ms, width, height, pixels, color_format, rotation)

Preferred constructor. timestamp_ms (int, milliseconds) identifies the frame and must strictly increase across successive process() calls; color_format is an af.Frame.ColorFormat; rotation an af.Frame.Rotation (pass af.Frame.Rotation.upright for unrotated input).

af.Frame(width, height, pixels, color_format, timestamp_ms)

af.Frame(width, height, pixels, color_format, rotation, timestamp_ms)

Legacy argument orders, kept for backward compatibility β€” prefer the timestamp-first form.

frame.timestamp()

Returns the timestamp in milliseconds.

af.Frame.ColorFormat

rgb, bgr, rgba, bgra, yuv_nv21, yuv_i420, yuv_yuy2, gray β€” pixel channel orderings; OpenCV images are bgr.

af.Frame.Rotation

upright, cw_90, cw_180, cw_270 β€” how the image is rotated (clockwise) relative to an upright face. Declaring the rotation avoids rotating pixel buffers yourself.

Detectors

af.SyncFrameDetector β€” synchronous

Processes every pushed frame (never drops) and invokes callbacks on the thread that called process(), which blocks until the frame’s callbacks complete. Best for offline video analysis.

af.SyncFrameDetector(max_num_faces=1, max_thread_pool_size=0)

af.SyncFrameDetector(baseline_mode, max_num_faces=1, max_thread_pool_size=0)

baseline_mode is an af.BaselineMode.

MethodDescription
start(license_key="")validates the license and initializes processing; an empty string falls back to the AFFECTIVA_LICENSE_KEY environment variable
stop()stops processing and deallocates resources
reset()re-initializes for a new session; timestamps may restart at 0
is_running()True after start() and before stop()
process(frame)processes an af.Frame; callbacks fire before it returns
set_face_listener(listener)register an af.FaceListener
set_image_listener(listener) Deprecatedregister an af.ImageListener
enable_feature(feature) / enable_features({...})add to the enabled feature set
disable_feature(feature) / disable_features({...})remove from the enabled feature set
is_enabled(feature) / is_enabled({features})True if the feature β€” or all features in the set β€” are enabled
get_enabled_features()the currently enabled set

af.FrameDetector β€” asynchronous

Queues frames for a native background thread with real-time semantics: if input outpaces process_frame_rate, excess frames are dropped. Callbacks arrive on the background thread.

af.FrameDetector(process_frame_rate=30.0, max_num_faces=1, max_thread_pool_size=0)

af.FrameDetector(baseline_mode, process_frame_rate=30.0, max_num_faces=1, max_thread_pool_size=0)

Methods are the same as af.SyncFrameDetector with three differences:

MethodDescription
is_feature_enabled(feature)True if the feature is enabled (this class’s spelling of is_enabled)
are_features_enabled({features})True only if all given features are enabled
process(frame) / stop()release the GIL while native code runs, so your capture loop is not blocked

af.Face

One tracked face in a processed frame, delivered to your listener as a dict keyed by face id.

MethodReturns
get_id()int β€” tracking identifier, stable while the face stays in view
get_confidence()float β€” confidence in the presence of the face, 0–100
get_expressions()dict {af.Expression: float}
get_emotions()dict {af.Emotion: float}
get_measurements()dict {af.Measurement: float}
get_qualities()dict {af.Quality: float}
get_bounding_box()list of two af.Points: top-left, then bottom-right
get_face_points()dict {af.FacePoint: af.Point}

af.Point

A 2-D pixel coordinate with read/write attributes x and y. Constructors: af.Point(), af.Point(x, y).

af.BoundingBox

A rectangle built from two points: af.BoundingBox(tl, br), with get_top_left() and get_bottom_right().

Listeners

af.FaceListener

Subclass it, override all three methods, and register with set_face_listener() before start(). Keep a reference to the listener for as long as it is registered.

CallbackCalled when
face_found(timestamp, face_id)the tracker starts tracking a new face
face_lost(timestamp, face_id)a tracked face is no longer found
results_updated(faces, frame)a frame has been processed; faces is dict {int: af.Face}, frame the processed af.Frame

af.ImageListener Deprecated

Superseded by af.FaceListener. Callbacks: results_updated(faces, frame) and image_captured(frame) (fires for every input frame, including frames the asynchronous detector chose not to process).

Enumerations

The tables below give concise definitions. For a full explanation of each metric β€” the facial actions behind it, value semantics, and interpretation guidance β€” see the Metrics guide.

af.Feature

faces, expressions, emotions β€” the metric families a detector can compute. Face tracking metrics (bounding box, face points, measurements, qualities, confidence) are always delivered for tracked faces.

af.Expression

Continuous metrics range 0 (absent) to 100 (fully present); event metrics report 0 or 100.

ValueDescriptionRange
smileupward pull of the lip corners0–100
inner_brow_raiseraising of the inner brow corners0–100
brow_raiseraising of both brows0–100
brow_furrowlowering/drawing together of the brows0–100
nose_wrinklewrinkling of the nose0–100
upper_lip_raiseraising of the upper lip0–100
lip_corner_depressordownward pull of the lip corners0–100
chin_raiseupward push of the chin boss0–100
lip_puckerpuckering of the lips0–100
lip_presspressing the lips together0–100
lip_suckpulling the lips inward0–100
mouth_openparting of the lips0–100
smirkasymmetric lip corner pull0–100
eye_closureboth eyelids closed0–100
speakingthe person is speaking0–100
attentionvisual attention toward the camera (head orientation)0–100
eye_widenwidening of the eyes0–100
cheek_raiseraising of the cheeks0–100
lid_tightentightening of the eyelids0–100
dimplertightening of the lip corners (dimpling)0–100
lip_stretchhorizontal stretching of the lips0–100
jaw_droplowering of the jaw0–100
blinka blink occurred0 / 100
blink_rateblinks per minute; NaN during the first 10Β s after a face is detectedblinks/min
yawna yawn occurred0 / 100
paincontinuous estimate that the person is expressing pain; 50 is the model’s decision threshold, so values above 50 mean pain is more likely present than not0–100

af.Emotion

0–100 except the valence metrics (βˆ’100 to +100).

ValueDescriptionRange
joydegree of expressed joy0–100
feardegree of expressed fear0–100
disgustdegree of expressed disgust0–100
sadnessdegree of expressed sadness0–100
angerdegree of expressed anger0–100
surprisedegree of expressed surprise0–100
contemptdegree of expressed contempt0–100
neutraldegree to which the face shows no emotion0–100
sentimentalitydegree of expressed sentimentality0–100
confusiondegree of expressed confusion0–100
valenceoverall positivity (+) or negativity (βˆ’) of the expressionβˆ’100–100
engagementoverall facial expressiveness0–100
conversational_valencevalence variant tuned for conversational settingsβˆ’100–100
conversational_engagementengagement variant tuned for conversational settings0–100
adaptive_valencevalence variant that adapts to the individual’s baselineβˆ’100–100
adaptive_engagementengagement variant that adapts to the individual’s baseline0–100

af.Measurement

ValueDescriptionUnit
pitchpositive = head tilted up, negative = tilted downdegrees
yawpositive = head turned to the person’s right, negative = to their leftdegrees
rollpositive = head tilted to the person’s left, negative = to their rightdegrees
interocular_distancedistance between the two outer eye corner landmarkspixels

af.FacePoint

outer_right_eye, outer_left_eye, nose_tip, chin_tip β€” landmark identifiers for get_face_points().

af.Quality

brightness (0–100) β€” useful for detecting under- or over-exposed capture conditions.

af.BaselineMode

OFF β€” metrics calculated statically (default); ON β€” metrics calculated against a rolling-average “baseline” that adapts to the individual’s neutral expression. Passed as the first constructor argument of either detector.

Errors & threading

  • Native SDK exceptions are raised as RuntimeError, with nested causes appended to the message (e.g. a missing license key on start()).
  • The C++ ProcessStatusListener is not exposed in Python. With af.SyncFrameDetector, errors propagate directly out of process(); prefer it when robust error handling matters.
  • With af.FrameDetector, listener callbacks run on the SDK’s background thread β€” hand results to your main thread via a queue.Queue or similar rather than touching shared state directly.