Skip to Content
ActionsopenFaceCamera

openFaceCamera

openFaceCamera action opens the device camera with real-time face detection. It automatically captures an image when the face is properly aligned (position, angle, etc.), making it ideal for selfies, profile photos, or any face-detection task on mobile and web. Use the id property to bind the captured image result (e.g. to a variable or data binding).

Setup in Ensemble Studio

  1. Go to https://studio.ensembleui.com/ 
  2. Open your app
  3. From the left sidebar, click Build & Deploy
  4. In the Build Settings tab, enable the Face Camera module/feature and update.
  5. If building for iOS: switch to the iOS tab and add the required camera usage description (e.g. “We use the camera to capture your face for verification”) and any face-related privacy descriptions

Properties

PropertyTypeDescription
idstringCamera ID used to bind captured results (for example ${myFaceCamera.files}).
onCaptureactionExecutes when an image is captured. Captured files are available via event.data.files.
onErroractionExecutes on error. Error message is available via event.error.
optionsobjectAdditional configuration for camera and detection.

options

PropertyTypeDescription
initialCamerastringWhich lens to start with: front (default), back
messagestringMessage shown above camera preview
messageStyleobjectText style for message
showControlsbooleanShow/hide all camera controls. Default true
showCaptureControlbooleanShow/hide capture button. Default true
showFlashControlbooleanShow/hide flash control. Default true
showCameraLensControlbooleanShow/hide camera switch control. Default true
showStatusMessagebooleanShow/hide face detection status text. Default true
indicatorShapestringFace indicator shape: circle, square
autoDisableCaptureControlbooleanDisable capture while no valid face is detected. Default false
autoCapturebooleanAutomatically capture when face qualifies. Default false
imageResolutionstringCapture resolution: low, medium, high (default), veryHigh, ultraHigh, max
defaultFlashModestringInitial flash mode: off (default), auto, always
orientationstringCamera orientation: portraitUp (default), portraitDown, landscapeLeft, landscapeRight
performanceModestringFace detector mode: fast (default), accurate
accuracyConfigobjectFine-grained face detection thresholds. Web only. See options.accuracyConfig below.

options.accuracyConfig

Note: accuracyConfig is supported only on web.

The following properties are verified in code as parsed and used by web face detection:

PropertyTypeDefaultDescription
detectionThresholdnumber0.6Minimum confidence score for a valid face detection
intersectionRatioThresholdnumber0.9Minimum overlap ratio between detected face and expected region
extraHeightFactornumber0.3Additional height factor for face bounding box
inputSizenumber224Input image size used by detector
landmarkRationumber0.95Minimum landmark alignment/visibility ratio
frameMarginnumber0.05Margin ratio to ensure face is not too close to frame edges
tiltAngleThresholdnumber6Maximum allowed tilt angle in degrees
horizontalCenterTolerancenumber0.08Allowed horizontal centering tolerance
earThresholdnumber0.25Eye aspect ratio threshold for open-eye validation
minFaceWidthRationumber0.18Minimum face width ratio relative to frame
maxFaceWidthRationumber0.82Maximum face width ratio relative to frame
qualityPassThresholdnumber0.8Minimum quality score required to pass
yawLowerThresholdnumber0.85Lower yaw ratio bound
yawUpperThresholdnumber1.15Upper yaw ratio bound

Alias keys also supported by parser:

  • threshold -> detectionThreshold
  • yaw -> yawUpperThreshold
  • tilt -> tiltAngleThreshold
  • minFaceSize -> minFaceWidthRatio

Usage Examples

1. Basic capture and preview

Open the face camera, bind the result to an ID, and preview the captured image.

View: header: title: "Action: openFaceCamera" styles: scrollableView: true body: Column: styles: { gap: 16, padding: 24 } children: - Button: label: Open Face Camera onTap: openFaceCamera: id: myFaceCamera - Conditional: conditions: - if: ${myFaceCamera.files.length > 0} Image: source: ${myFaceCamera.files[0].path}

2. Capture with common options

Configure the most common face camera options and log the result when a capture succeeds.

- Button: label: Open Face Camera with Options onTap: openFaceCamera: id: myFaceCamera options: initialCamera: front performanceMode: fast imageResolution: high defaultFlashMode: off orientation: portraitUp message: "Align your face" messageStyle: color: 0xFFFFFFFF indicatorShape: circle showStatusMessage: true showControls: true showCaptureControl: true showFlashControl: true showCameraLensControl: true onCapture: executeCode: body: | console.log('Face camera captured image with id: ' + myFaceCamera.files); onError: showToast: message: "Error capturing image: ${event.error}"

3. Auto-capture and upload

Automatically capture once the face is valid, then upload the captured file.

- Button: label: Auto Capture and Upload onTap: openFaceCamera: id: captureMedia options: autoCapture: true performanceMode: accurate message: "Hold still for capture" onCapture: uploadFiles: id: uploader files: ${captureMedia.files[0]} uploadApi: fileUploadApi fieldName: file - Markdown: text: ${uploader.body} API: fileUploadApi: inputs: - url uri: ${url} method: POST

4. Web accuracy config

Use strict face detection thresholds for web capture.

- Button: label: Open Camera (web, strict) onTap: openFaceCamera: id: cameraWithFaceDetection options: initialCamera: front autoCapture: false performanceMode: accurate accuracyConfig: detectionThreshold: 0.5 intersectionRatioThreshold: 0.9 extraHeightFactor: 0.6 inputSize: 224 landmarkRatio: 0.95 frameMargin: 0.05 tiltAngleThreshold: 6 horizontalCenterTolerance: 0.08 earThreshold: 0.25 minFaceWidthRatio: 0.18 maxFaceWidthRatio: 0.82 qualityPassThreshold: 0.8 yawLowerThreshold: 0.85 yawUpperThreshold: 1.15 message: "Align your face in the square" messageStyle: color: "#FF0000" fontSize: 20 onCapture: uploadFiles: id: uploader files: ${cameraWithFaceDetection.files[0]} uploadApi: fileUploadApi fieldName: file onError: showToast: message: "Error capturing image: ${event.error}"

To learn more about openCamera functionalities, test it out here in Ensemble Kitchen Sink  app.

Last updated on