Summary: Nested Classes | Ctors | Methods | Inherited Methods | [Expand All]
public abstract class

# Detector

extends Object

java.lang.Object
↳ | com.google.android.gms.vision.Detector<T>

Known Direct Subclasses BarcodeDetector, FaceDetector, MultiDetector, TextRecognizer
BarcodeDetector | Recognizes barcodes (in a variety of 1D and 2D formats) in a supplied `Frame`.
FaceDetector | Detector for finding `Faces` in a supplied image.
MultiDetector | A multi-detector is used to combine multiple detectors, so that multiple detectors can be used together on a frame or frames received from a source within a pipeline.
TextRecognizer | Finds and recognizes text in a supplied `Frame`.

## Class Overview

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.

## Summary

Nested Classes
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 Constructors
| Detector()

Public Methods
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.

[Expand] Inherited Methods
From class java.lang.Object
Object | clone()
boolean | equals(Object arg0)
void | finalize()
final Class<?> | getClass()
int | hashCode()
final void | notify()
final void | notifyAll()
String | toString()
final void | wait(long arg0, int arg1)
final void | wait(long arg0)
final void | wait()

## Public Constructors

#### public Detector ()

## Public Methods

#### public abstract SparseArray<T> detect (Frame frame)

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 ()

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 `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)

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 ()

Shuts down the detector, releasing any underlying resources.

#### public boolean setFocus (int id)

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 `getDetectedItems()`.

#### public void setProcessor (Processor<T> processor)

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.