βΆοΈ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:
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
-1which means that it keeps checking until a finger has been detected.Pulse detection Check if a pulse is present. When no pulse has been detected for 10 seconds, the calibration phase will start.
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.
Recording During the recording phase, the Camera SDK algorithm calculates the PPG data by processing the mobile device's camera feed.
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.
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.
Add this to the Info.plist file:
<key>NSCameraUsageDescription</key>
<string>Your own description of the purpose</string>For more information regarding these iOS permissions, check the official iOS 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
As you can see in the snippet, we used the react-native-permissions library. The installation guide can be found in the readme of the library's repository.
The following snippet from the Android documentation on requesting runtime permissions shows how to request the CAMERA permission:
The following snippet has been extracted from the Apple Documentation and shows how to check if the user has given permission to use the camera:
No specific action needed for the Cordova SDK. The SDK will automatically ask permission to the user if the permissions are configured correctly in the previous step.
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.
To install the Camera SDK, you will need to have access to the Camera SDK git repository.
In your project, if you are using yarn or npm you need to create a file called .npmrc at the root level of your project and add these lines. Replace {AUTH_TOKEN} with the personal access token you've received from FibriCheck
Alternatively, this file can be added/edited in your home directory and it will be applied to all projects.
Explanation from GitHub on how to add your token can be found here.
using npm:
using yarn:
You will receive access to the Native Camera SDK repository. This repository will contain the source files that you can include directly in your project.
To install the Camera SDK for Cordova, you will receive an authentication token to access the private npm package hosted on GitHub Packages.
To include the cordova-camera-sdk package in your application, follow these steps:
Add a .npmrc file to the root of your project with the following content:
Replace ${AUTH_TOKEN} with a valid authentication token.
Next, add the package to your project using npm or yarn
After completing the above steps, the FibriCheck Camera SDK is available in your code in the cordova.plugins object:
For iOS, the minimal deployment target is iOS 13. Make sure to add the following configuration to the config.xml, where the value must be >=13:
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, aNoActivePrescriptionErrorwill 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.
The Camera SDK provides a React Native Component that you can integrate quickly in your application.
You can use the RNFibriCheckView exported from the @fibricheck/react-native-camera-sdk 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, aNoActivePrescriptionErrorwill 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.
The measurement context is prefilled here, but needs to be completed by the user. The best practice is to add this at a later stage with
sdk.updateMeasurementContext. More information about this can be found in the Measurement Structure.
The FibriChecker class is the main class that you have to use to implement FibriCheck in your application.
The iOS Native SDK is written in Objective-C. Newer iOS applications are typically developed in Swift. It's possible to use Objective-C files and Swift files in the same project. See the Apple documentation for more info.
The following code snippet is a working example that will show the heart rate, calculated using the Native SDK, on the main screen:
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:
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.
There is a library react-native-vision-camera that is able to select the correct lens. The following snippet provides an example of how this can be implemented:
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