5. Camera
To use ARGear, you must provide camera configuration information and video frames to ARGear. Based on that information, ARGear applies AR functions such as face tracking, segmentation, etc. on top of the received frames as configured in ARGInferenceConfig.Feature.
The sample code below describes an example of camera configuration and how to feed video frames to ARGear.
Java
Kotlin
1
ReferenceCamera.CameraListener cameraListener = new ReferenceCamera.CameraListener() {
2
@Override
3
public void setConfig(int previewWidth,
4
int previewHeight,
5
float verticalFov,
6
float horizontalFov,
7
int orientation,
8
boolean isFrontFacing,
9
float fps) {
10
argsession.setCameraConfig(new ARGCameraConfig(previewWidth,
11
previewHeight,
12
verticalFov,
13
horizontalFov,
14
orientation,
15
isFrontFacing,
16
fps));
17
}
18
19
// region - for camera api 1
20
@Override
21
public void feedRawData(byte[] data) {
22
// Send preview frame raw data from camera device to ARGear
23
argsession.feedRawData(data);
24
}
25
// endregion
26
27
// region - for camera api 2
28
@Override
29
public void feedRawData(Image data) {
30
// Send preview frame image from camera device to ARGear
31
argsession.feedRawData(data);
32
}
33
// endregion
34
};
Copied!
1
private var cameraListener: ReferenceCamera.CameraListener = object : ReferenceCamera.CameraListener {
2
override fun setConfig(
3
previewWidth: Int,
4
previewHeight: Int,
5
verticalFov: Float,
6
horizontalFov: Float,
7
orientation: Int,
8
isFrontFacing: Boolean,
9
fps: Float
10
) {
11
argsession.setCameraConfig(
12
ARGCameraConfig(
13
previewWidth,
14
previewHeight,
15
verticalFov,
16
horizontalFov,
17
orientation,
18
isFrontFacing,
19
fps
20
)
21
)
22
}
23
24
// region - for camera api 1
25
override fun feedRawData(data: ByteArray?) {
26
argsession.feedRawData(data)
27
}
28
// endregion
29
30
// region - for camera api 2
31
override fun feedRawData(data: Image?) {
32
argsession.feedRawData(data)
33
}
34
// endregion
35
}
Copied!
Sample code of a camera class that calls updateFaceRects and feedRawData functions is written below.

Camera API 1 Sample Code

Java
Kotlin
<Camera API 1 Sample Code>
1
private class CameraPreviewCallback implements Camera.PreviewCallback {
2
@Override
3
public void onPreviewFrame(byte[] data, Camera camera) {
4
listener.feedRawData(data.array());
5
}
6
}
Copied!
1
private inner class CameraPreviewCallback : PreviewCallback {
2
override fun onPreviewFrame(
3
data: ByteArray,
4
camera: Camera
5
) {
6
listener?.feedRawData(data?.array())
7
}
8
}
Copied!

Camera API 2 Sample Code

Java
Kotlin
<Camera API 2 Sample Code>
1
private CameraCaptureSession.CaptureCallback mCaptureCallback
2
= new CameraCaptureSession.CaptureCallback() {
3
4
@Override
5
public void onCaptureProgressed(CameraCaptureSession session,
6
CaptureRequest request,
7
CaptureResult partialResult) {
8
}
9
10
@Override
11
public void onCaptureCompleted(@NonNull CameraCaptureSession session,
12
@NonNull CaptureRequest request,
13
@NonNull TotalCaptureResult result) {
14
}
15
};
16
17
18
private final ImageReader.OnImageAvailableListener mOnImageAvailableListener
19
= new ImageReader.OnImageAvailableListener() {
20
@Override
21
public void onImageAvailable(final ImageReader reader) {
22
mHandler.post(new Runnable() {
23
@Override
24
public void run() {
25
final Image image = reader.acquireLatestImage();
26
if (image != null) {
27
listener.feedRawData(image);
28
image.close();
29
}
30
}
31
});
32
}
33
};
Copied!
1
private val mCaptureCallback: CaptureCallback = object : CaptureCallback() {
2
3
override fun onCaptureProgressed(
4
session: CameraCaptureSession,
5
request: CaptureRequest,
6
partialResult: CaptureResult
7
) {
8
}
9
10
override fun onCaptureCompleted(
11
session: CameraCaptureSession,
12
request: CaptureRequest,
13
result: TotalCaptureResult
14
) {
15
}
16
}
17
18
19
private val mOnImageAvailableListener =
20
OnImageAvailableListener { reader ->
21
handler?.post {
22
val image = reader.acquireLatestImage()
23
if (image != null) {
24
listener.feedRawData(image)
25
image.close()
26
}
27
}
28
}
Copied!
Last modified 10mo ago