Skip to content

Capture Session

Adding Capture Session

1
2
3
4
5
6
7
8
9
// ViewController.swift
import MobaiCore

let captureSession: CaptureSessionView = {
    let captureSession = CaptureSessionView(frame: CGRect.init(x: 0, y: 0, width: 100, height: 100))
    captureSession.translatesAutoresizingMaskIntoConstraints = false
    captureSession.contentMode = UIView.ContentMode.scaleAspectFill
    return captureSession
}()

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
// MainActivity.java
private CaptureSessionFragment captureSession;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    this.captureSession = (CaptureSessionFragment) getSupportFragmentManager().findFragmentById(R.id.mob_capture_session);
}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
<!-- activity_main.xml -->
<fragment android:name="bio.mobai.library.capture.CaptureSessionFragment"
    android:id="@+id/mob_capture_session"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    android:layout_height="200dp"
    android:layout_width="200dp"
    />

Starting the camera preview

1
self.captureSession.setupCaptureSession()
1
this.captureSession.setupCaptureSession();

Starting the capture session

1
2
3
4
5
self.captureSessionView.startCaptureSession { (sessionPayload, error) in
    if (error != nil) {
        // Use session payload
    }
}
1
2
3
this.captureSession.startCaptureSession(sessionPayload -> {
    // Use session payload
}

Configure Capture Session

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
let captureSession: CaptureSessionView = {
    let captureSession = CaptureSessionView(frame: CGRect.init(x: 0, y: 0, width: 100, height: 100))
    captureSession.translatesAutoresizingMaskIntoConstraints = false
    captureSession.contentMode = UIView.ContentMode.scaleAspectFill
    captureSession.encoding = .JPEG
    captureSession.faceCaptureEnabled = true
    captureSession.numFramesBeforeFaceImage = 9
    captureSession.padCaptureEnabled = true
    captureSession.targetResolutionPad = .hd1280x720
    captureSession.numFramesPad = 5
    captureSession.frameInterval = 4
    captureSession.faceQualityEnabled = false
    return captureSession
}()
1
2
3
4
5
6
7
8
9
CaptureSessionFragment captureSession = (CaptureSessionFragment) getSupportFragmentManager().findFragmentById(R.id.mob_capture_session);
    captureSession.setEncoding(Bitmap.CompressFormat.JPEG);
    captureSession.setFaceCaptureEnabled(true);
    captureSession.setNumFramesBeforeFaceImage(9);
    captureSession.setPadCaptureEnabled(true);
    captureSession.setNumFramesPad(5);
    captureSession.setFrameInterval(4);
    captureSession.setTargetResolutionPad(new Size(720, 1280));
    captureSession.setFaceQualityEnabled(true);