Detector

Also: "vision"
public abstract class Detector extends Object
Known Direct Subclasses

Detector is the base class for implementing specific detector instances, such as a barcode detector or face detector. A detector receives a Frame as input, and produces a number of detected items as output. The Detector implementation is generic, parameterized by T, the type of the detected items.

A detector may be used to run detection synchronously given a frame, like this:

SparseArray<Foo> foos = detector.detect(frame);
 
Alternatively, a detector may also be used within a pipeline structure, in conjunction with sources (e.g., CameraSource) and processors (e.g., MultiProcessor), enabling you to construct fairly advanced detection pipelines with minimal coding.

For example, the code below creates and starts a pipeline that continuously receives preview frames from a camera source, runs detection on the frames, and manages tracking an individual detected item over time via a developer-defined "FooTracker" instance.

detector.setProcessor(
   new MyFooFocusingProcessor(
     detector,
     new FooTracker()));

 CameraSource cameraSource = new CameraSource.Builder(context, detector)
   .build()
   .start();
 
Where "MyFooFocusingProcessor" is a FocusingProcessor implementation and "FooTracker" is a Tracker callback for receiving notifications on the detected "Foo" instance.

Nested Class Summary

class Detector.Detections<T> Detection result object containing both detected items and the associated frame metadata. 
interface Detector.Processor<T> Interface for defining a post-processing action to be executed for each detection, when using the detector as part of a pipeline (see the class level docs above). 

Public Constructor Summary

Public Method Summary

abstract SparseArray<T>
detect(Frame frame)
Analyzes the supplied frame to find target item instances (e.g., the face detector finds faces).
boolean
isOperational()
Indicates whether the detector has all of the required dependencies available locally in order to do detection.
void
receiveFrame(Frame frame)
Pipeline method (see class level documentation above) for receiving frames for detection.
void
release()
Shuts down the detector, releasing any underlying resources.
boolean
setFocus(int id)
Sets the ID of the detected item in which to exclusively track in future use of the detector.
void
setProcessor(Processor<T> processor)
Pipeline method (see class level documentation above) which sets the Detector.Processor instance.

Inherited Method Summary

Public Constructors

public Detector ()

Also: "vision"

Public Methods

public abstract SparseArray<T> detect (Frame frame)

Also: "vision"

Analyzes the supplied frame to find target item instances (e.g., the face detector finds faces). Subclasses implement this method for calling specific detection code, returning result objects with associated tracking ID mappings.

Returns
  • mapping of int to detected object, where the int domain represents the ID of the associated item. If tracking is enabled, as the same object is detected in consecutive frames, the detector will return the same ID for that item.

public boolean isOperational ()

Also: "vision"

Indicates whether the detector has all of the required dependencies available locally in order to do detection.

When an app is first installed, it may be necessary to download required files. If this returns false, those files are not yet available. Usually this download is taken care of at application install time, but this is not guaranteed. In some cases the download may have been delayed.

If your code has added a processor, an indication of the detector operational state is also indicated with the Detector.Detections.detectorIsOperational() method. You can check this in your app as it processes detection results, and can convey this state to the user if appropriate.

Returns
  • true if the detector is operational, false if the dependency download is in progress

public void receiveFrame (Frame frame)

Also: "vision"

Pipeline method (see class level documentation above) for receiving frames for detection. Detection results are forwarded onto a processor that was previously registered with this class (see setProcessor(Detector.Processor)).

Alternatively, if you are just looking to synchronously run the detector on a single frame, use detect(Frame) instead.

public void release ()

Also: "vision"

Shuts down the detector, releasing any underlying resources.

public boolean setFocus (int id)

Also: "vision"

Sets the ID of the detected item in which to exclusively track in future use of the detector. This can be used to avoid unnecessary work in detecting all items in future frames, when it's only necessary to receive results for a specific item. After setting this ID, the detector may only return results for the associated tracked item. When that item is no longer present in a frame, the detector will revert back to detecting all items.

Optionally, subclasses may override this to support optimized tracking.

Parameters
id tracking ID to become the focus for future detections. This is a mapping ID as returned from detect(Frame) or received from Detector.Detections.getDetectedItems().

public void setProcessor (Processor<T> processor)

Also: "vision"

Pipeline method (see class level documentation above) which sets the Detector.Processor instance. This is used in creating the pipeline structure, associating a post-processor with the detector.