Object Tracker

An object tracker follows detected objects during the intermediate frames between model executions and matches the existing objects to new detections. This reduces the possibility of recognitions being duplicated for the same object in different frames. It can also provide a smoother experience by updating an object's location more frequently than a model can execute.

The following code snippet provides an example of tracking using LSTrackerManager(implemented by LSTrackerManagerImpl) with detections from LSModelManager(implemented by LSModelManagerParallel):

import android.graphics.Bitmap;

import com.here.see.common.util.permission.AuthorizationException;
import com.here.see.livesense.manager.LSModelManagerParallel;
import com.here.see.livesense.manager.LSTrackerManagerImpl;
import com.here.see.livesense.domain.Recognition;
import com.here.see.livesense.tracker.TrackedRecognition;

import java.io.IOException;
import java.util.List;

public class RecognitionWithTracking {
    private LSModelManagerParallel managerParallel;
    private LSTrackerManagerImpl trackerManager;

    public void init() {
        // Initialize manager and tracker
        managerParallel = new LSModelManagerParallel(new ManagerListener() {
            @Override
            public void onError(int i, Throwable throwable) {
                android.util.Log.e("Recognition", "Error in inference with modelId: " + i, throwable);
            }

            @Override
            public void onRecognitions(int modelId, int imageId, List<Recognition> list, long runTime) {
                // Process new detections
            }
        });
        trackerManager = new LSTrackerManagerImpl();
        managerParallel.setTrackerManager(trackerManager);
        managerParallel.addModel(LiveSenseModel.ROAD_BASICS, new RoadBasicsModel.Options(), 0.45f);

    }

    public void close() {
        managerParallel.close();
        if (trackerManager != null) {
            trackerManager.close();
        }
    }

    /**
     * @param frame          RGBA8888 image
     * @param frameRotation  Clockwise rotation to reach frame's natural orientation as a multiple of 90 degrees
     */
    public List<TrackedRecognition> recognizeWithTracking(Bitmap frame, byte[] frameLuminance, int frameRotation) {
        // Perform detection
        managerParallel.offerImage(frame, frameRotation);
        // Return current list of tracked recognitions for further processing/display
        return trackerManager.getTrackedObjects();
    }
}

results matching ""

    No results matching ""