▢️Introduction

The Camera SDK is a PPG recording module that you can use in combination with the FibriCheck Cloud SDK. A FibriCheck measurement contains PPG data. To obtain this data, the Camera SDK communicates with the native iOS/Android camera layer, processes this data, and returns an object to submit to our backend for analysis. Multiple properties and listeners can be adjusted/attached for improving the visualization/customization of the process.

The different phases of a FibriCheck measurement are:

  1. Finger detection Check for the presence of a finger on the camera. You can set the timeout to 0 to skip this phase. By default, this value is set to -1 which means that it keeps checking until a finger has been detected.

  2. Pulse detection Check if a pulse is present. When no pulse has been detected for 10 seconds, the calibration phase will start.

  3. Calibration When performing a measurement, a baseline needs to be calculated. When this baseline has been calculated, the calibration is ready and recording can start.

  4. Recording During the recording phase, the Camera SDK algorithm calculates the PPG data by processing the mobile device's camera feed.

  5. Processing When the recording is finished, some additional processing needs to be done on the measurement. When done, a measurement object is presented via the onMeasurementProcessed event.

The Camera SDK is currently available for Flutter, React Native, Cordova, iOS and Android

Installation

Set the correct permissions

The recording makes use of the device's camera. So you'll need to make sure that your application has access to the camera.

Depending on the operating system, you will need to make changes to the project's configuration file.

Add this to the AndroidManifest.xml file:

<uses-permission android:name="android.permission.CAMERA" />

For more information regarding Android permissions, check the official Android documentation.

Next to modifying the project configuration, your app will also have to ask the user to allow using the camera:

To ask for the correct permissions we use the permission_handler package.

Add the following snippet to your Podfile:

Then in your code you can request the camera permission:

For more details, you can take a look at the permission_handler documentation

Install the Camera SDK

In your project, you can add the package below to the pubspec.yaml file. Replace {TOKEN} with the personal access token you've received from FibriCheck.

Perform your first measurement

In this paragraph, we explain how you can perform a measurement

The Camera SDK provides a widget that has the following structure:

You can use the FibriCheckView exported from the package:camera_sdk/fibri_check_view.dart package to perform a measurement and hook up sdk.postMeasurement to post the data returned from the camera to the backend in the onMeasurementProcessed event.

  • Before taking a measurement, you need to check if you are entitled to perform a measurement. This can be achieved by invoking sdk.canPerformMeasurement. If you try to execute a measurement when you are not entitled, a NoActivePrescriptionError will be thrown. So make sure you've Activated a Prescription.

  • It is highly recommended to provide the camera SDK version as a second argument, as shown in the example.

In rare cases, it can occur that the motion sensors don't provide the correct data. Because the algorithm requires motion sensor data to be available, an onMeasurementError event will be thrown in this case. Look here for more information.

Device Requirements

A full FibriCheck measurement consists of an on-device data acquisition step and a cloud data analysis step, performed by an AI algorithm. The on-device algorithms extracts a raw measurement from the the camera feed.

The use of the SDK has no significant impact on storage or memory usage of the device. The frames from the camera feed are processed on-the-fly by memory-efficient algorithms.

During the measurement there will be a significant CPU usage caused by the on-the-fly processing of the camera feed. However these processing algorithms also power the FibriCheck application which is broadly available on low-end and high-end smartphones. In this respect, we don't expect any performance issues by using the Camera SDK's in your application.

The following table lists the required minimum mobile operating system versions, and minimum framework versions:

Platform
Minimum OS (and framework)

Android

Android KitKat (4.4) API Level 19

iOS

iOS 11 (Sept. 17)

Important Remarks

Camera selection

Modern phones have multiple cameras. The Camera SDK uses the default capture device that is able to record video content.

To guide the user in putting their finger on the correct camera, it's recommended to show the camera output as a "peephole" in the interface at the start of a measurement.

In order to aid the user in using the correct camera lens, you can provide a preview of the relevant camera via the following package: https://pub.dev/packages/camera.

The Camera SDK uses the default camera.

Make sure to catch all measurement errors

An ongoing measurement will stop when a measurement error occurs. Make sure that an onMeasurementError has been defined. See the onMeasurementError documentation for more information

Framework-specific remarks

Drawing on the JS Thread

When benchmarking the SDK, we noticed that drawing on the JS Thread while taking a measurement caused severe spikes in the processing power. This will results in a bad quality measurement. So when creating a visualisation, for example counting down the seconds that are left in a measurement, make sure you are not drawing on the JS Thread. Either make use of Native Driver or use React Reanimated. When using third party libraries for creating animations, make sure they also offload the drawing from the JS Thread.

Not using Hermes

When benchmarking the SDK, we noticed that Hermes also had a big impact on the performance of low-end devices. So we advice you to enable it if possible. Instructions can be found in their documentation.

Visualizing the ongoing measurement

The SDK emits an onSampleReady event on each processed frame. The event contains a filtered ppg value and a raw measurement value of the latest received video frame.

You can use these values to visualize the PPG graph to the user during the measurement. Depending on the lightning conditions, the variance of the ppg values can be very low during most part of the measurement (decimal values between -1 and +1). Make sure to apply appropriate scaling to the graph to correctly visualize the PPG measurement to the user. Avoid visualizing an apparently flat line.

Last updated