Android Studio Setup

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:

  1. Add dependencies to arguskit_core.arr, arguskit.arr, and arguskit_embedded_fd.arr. (File names may differ based on the library version.)

    1. Add libraries to your project:

      1. Click File > New > New Module.
      2. Click Import .JAR/.AAR Package, then click Next.
      3. Enter the location of the AAR file then click Finish.
    2. Make sure libraries are listed at the top of your settings.gradle file:

      • include :app, :arguskit_core, :arguskit, :arguskit_embedded_fd
    3. 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")
      }
    4. Click Sync Project with Gradle Files.

  2. 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" />
  3. 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}"
    }
  4. Optionally include arguskit_agl_player.aar.

    1. Repeat steps from 1.

    2. 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();

See Also