5. Camera

Camera configuration information and video related data should be provided in the form of CMSampleBufferRef to ARGear. Using the data, ARGear provides Face Tracking features.

Using AVCaptureSession, set up your camera first. Video frames and related face information can be obtained from AVCaptureVideoDataOutputSampleBufferDelegate and AVCaptureMetadataOutputObjectsDelegate in AVCaptureVideoDataOutput and AVCaptureMetadataOutput classes respectively.

Then, pass sampleBuffer and connection, or metadataObjects and connection received from Delegate functions above to updateSampleBuffer and updateMetadataObjects in ARGSession Interface.

The sample code below describes an example of camera configuration and how to feed video frames to ARGear.

Objective-C
Swift
Objective-C
// Sample Code. Example of Passing sampleBuffer and metadataObjects to ARGSession
ARGSession *argSession = [[ARGSession alloc] initWithARGConfig:argConfig error:&error];
// AVCaptureVideoDataOutput Delegate
- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection {
[argSession updateSampleBuffer:sampleBuffer fromConnection:connection];
}
// AVCaptureMetadataOutput Delegate
- (void)captureOutput:(AVCaptureOutput *)output didOutputMetadataObjects:(NSArray<__kindof AVMetadataObject *> *)metadataObjects fromConnection:(AVCaptureConnection *)connection {
[argSession updateMetadataObjects:metadataObjects fromConnection:connection];
}
Swift
// Sample Code. Example of Passing sampleBuffer and metadataObjects to ARGSession
// AVCaptureVideoDataOutput Delegate
func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) {
argSession?.update(sampleBuffer, from: connection)
}
// AVCaptureMetadataOutput Delegate
func metadataOutput(_ output: AVCaptureMetadataOutput, didOutput metadataObjects: [AVMetadataObject], from connection: AVCaptureConnection) {
argSession?.update(metadataObjects, from: connection)
}