The easiest way is to use the demo app as a project stub and continue development from there.
To manually set up your project to use the SAFR SDK, do the following:
Add dependencies to arguskit_core.arr, arguskit.arr, and arguskit_embedded_fd.arr. (File names may differ based on the library version.)
Add libraries to your project:
Make sure libraries are listed at the top of your settings.gradle file:
:app
, :arguskit_core
, :arguskit
, :arguskit_embedded_fd
Open the app module's build.gradle file and add a new line to the dependencies block as shown in the following snippet:
dependencies {
implementation project(":arguskit_core")
implementation project(":arguskit")
implementation project(":arguskit_embedded_fd")
}
Click Sync Project with Gradle Files.
Update AndroidManifest.xml.
<!-- Camera is required feature -->
<uses-feature android:name="android.hardware.camera" />
<!-- Add extra permissions -->
<uses-permission android:name="android.permission.CAMERA" />
<!-- Cloud communication -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- Local video playback using AGL player -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
Add other dependencies to your app's build.gradle:
dependencies {
implementation project(":arguskit_core")
implementation project(":arguskit")
implementation project(':arguskit_embedded_fd')
...
// Use the latest versions of these
// Needed for VisionCameraSource
implementation "com.google.android.gms:play-services-vision:${googlePlayServicesVersion}"
// Needed for CameraXSource
implementation "androidx.camera:camera-camera2:$cameraxVersion"
implementation "androidx.camera:camera-lifecycle:$cameraxVersion"
implementation "androidx.camera:camera-view:$cameraxViewVersion"
// Serialization
implementation "com.google.code.gson:gson:${gson}"
// Network stack
implementation "com.squareup.okhttp3:okhttp:${okhttp}"
}
Optionally include arguskit_agl_player.aar.
Repeat steps from 1.
Switch to AglVideoView and feed frames into ObjectTracker:
aglView.setVisibility(View.VISIBLE);
AglOptions options = new AglOptions();
//options.rotationOption = AglOptions.ROTATION_90;// Update rotation if needed
final String uri = RTSP_URI; // Or local video file path
aglView.init(uri, options, new AglVideoView.AglVideoViewDelegate() {
@Override
public void onFrameSizeChanged(int w, int h) {
Log.d(TAG, "Stream resolution " + w + "x" + h + " pixels");
}
@Override
public void onFrameUpdate(VideoFrame videoFrame) {
if (objectTracker != null) {
objectTracker.trackObjects(videoFrame);
}
}
@Override
public void onPreviewSizeChanged(float xScale, float yScale, int offsetLeft, int offsetTop) {
// Tell the overlay that screen geometry has changed
if (overlay != null) {
overlay.setCameraInfo(xScale, yScale, offsetLeft, offsetTop, CameraCharacteristics.LENS_FACING_FRONT);
}
}
@Override
public void onPlayerStreamEnd() {
Log.d(TAG, "onPlayerStreamEnd ");
}
@Override
public void onPlayerError(int error) {
Log.e(TAG, "onPlayerError " + error);
}
}
);
aglView.start();