Skip to content

External USB Camera in Face SDK

On Android, Regula Face SDK can use an external USB camera for Liveness and Face Capture. External USB support enables them on devices without a built-in camera.

USB support is off by default. To enable it, add the USB camera library to your project and configure Liveness or Face Capture as described below.

Warning

Using OTG adapters, USB hubs, or other intermediate connection devices may prevent the external USB camera from working correctly. For reliable use, connect the camera directly to the Android device using a single USB cable, without adapters or hubs.

Add USB Camera Library

Add the USB camera library dependency to your app-level build.gradle file:

build.gradle
implementation('com.regula.usb:api:8.5.+@aar')

You do not need to add USB host configuration to your application manifest. The library manifest already includes <uses-feature android:name="android.hardware.usb.host"/>.

Use USB Camera for Liveness

Set setUsbCamera(true) in LivenessConfiguration to use the external USB camera for Liveness:

val configuration = LivenessConfiguration.Builder()
    .setUsbCamera(true)
    .build()

FaceSDK.Instance().startLiveness(context, configuration) { response ->
}
LivenessConfiguration configuration = new LivenessConfiguration.Builder()
    .setUsbCamera(true)
    .build();

FaceSDK.Instance().startLiveness(context, configuration, livenessResponse -> {
});

Use USB Camera for Face Capture

Set setUsbCamera(true) in FaceCaptureConfiguration to use the external USB camera for Face Capture:

val configuration = FaceCaptureConfiguration.Builder()
    .setUsbCamera(true)
    .build()

FaceSDK.Instance().presentFaceCaptureActivity(context, configuration) { response ->
}
FaceCaptureConfiguration configuration = new FaceCaptureConfiguration.Builder()
    .setUsbCamera(true)
    .build();

FaceSDK.Instance().presentFaceCaptureActivity(context, configuration, faceCaptureResponse -> {
});

Configure USB Camera Preview and Rotation

Use the following settings to configure preview mirroring and camera rotation:

  • setUsbCameraMirrorPreview controls preview mirroring. The SDK mirrors the preview by default. Set the value to false to disable mirroring.
  • setCameraRotationAngle sets the camera rotation angle. The default angle is 0. You can set it to 90, 180, or 270 degrees.

Note

For Active Liveness, keep preview mirroring enabled because the user must turn their head during the check.

The following examples enable the USB camera and set additional preview options.

Liveness

val configuration = LivenessConfiguration.Builder()
    .setUsbCamera(true)
    .setUsbCameraMirrorPreview(false)
    .setCameraRotationAngle(90)
    .build()

FaceSDK.Instance().startLiveness(context, configuration) { response ->
}
LivenessConfiguration configuration = new LivenessConfiguration.Builder()
    .setUsbCamera(true)
    .setUsbCameraMirrorPreview(false)
    .setCameraRotationAngle(90)
    .build();

FaceSDK.Instance().startLiveness(context, configuration, livenessResponse -> {
});

Face Capture

val configuration = FaceCaptureConfiguration.Builder()
    .setUsbCamera(true)
    .setUsbCameraMirrorPreview(false)
    .setCameraRotationAngle(90)
    .build()

FaceSDK.Instance().presentFaceCaptureActivity(context, configuration) { response ->
}
FaceCaptureConfiguration configuration = new FaceCaptureConfiguration.Builder()
    .setUsbCamera(true)
    .setUsbCameraMirrorPreview(false)
    .setCameraRotationAngle(90)
    .build();

FaceSDK.Instance().presentFaceCaptureActivity(context, configuration, faceCaptureResponse -> {
});