Measurement preparation
After successfully installing, initializing and optionally configuring the SDK, your app should be ready to start the video measurement.
Before starting the measurement, the user should be instructed to keep a stable position without talking and changing the facial expression.
Initial conditions
After initialization, the SDK will start to analyze the video stream from the camera.
In order for the measurement to begin, the user needs to locate their face in the middle of the screen, in good lighting conditions. The embedded user interface displays face positioning hints, but you can also use the GetFaceState() and GetNormalizedFaceBbox() methods to check the current face position.
import 'package:shenai_sdk/shenai_sdk.dart';
// Get the current face state
final faceState = await ShenaiSdk.getFaceState();
switch (faceState) {
case FaceState.ok:
print("Face detected and centered");
break;
case FaceState.notCentered:
print("Face detected but not centered");
break;
case FaceState.tooClose:
print("Face is too close");
break;
case FaceState.tooFar:
print("Face is too far");
break;
case FaceState.notVisible:
print("Face is not visible");
break;
case FaceState.unknown:
print("Unknown face state");
break;
}
// Get the normalized bounding box of the face
final bbox = await ShenaiSdk.getNormalizedFaceBbox();
if (bbox != null) {
print("normalized face bounding box: ${bbox.x} ${bbox.y} ${bbox.width} ${bbox.height}");
}Starting the measurement
A measurement can be started either by clicking START in the embedded UI or by calling startMeasurement(). In the embedded UI, START remains inactive until the SDK is ready. For API-driven flows, mirror that behavior by checking isReadyToStartMeasurement() before calling startMeasurement() (for example, to enable/disable your own START button), or by polling readiness if you want to auto-start as soon as possible. Calling startMeasurement() before readiness is reached is a no-op. To stop an active measurement programmatically, call stopMeasurement().
If you want to start automatically as soon as possible, set the operating mode to MEASURE (either in initialization settings or via setOperatingMode), as described in OperatingMode.
if (await ShenaiSdk.isReadyToStartMeasurement()) {
ShenaiSdk.startMeasurement();
}
// ...
ShenaiSdk.stopMeasurement();Note that the actual measurement will not start until the user’s face is in the correct position.