java.lang.Object | |
↳ | com.google.android.gms.vision.Detector<T> |
![]() |
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 Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Detector.Detections<T> | Detection result object containing both detected items and the associated frame metadata. | ||||||||||
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 | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Analyzes the supplied frame to find target item instances (e.g., the face detector finds
faces).
| |||||||||||
Indicates whether the detector has all of the required dependencies available locally in order
to do detection.
| |||||||||||
Pipeline method (see class level documentation above) for receiving frames for detection.
| |||||||||||
Shuts down the detector, releasing any underlying resources.
| |||||||||||
Sets the ID of the detected item in which to exclusively track in future use of the detector.
| |||||||||||
Pipeline method (see class level documentation above) which sets the
Detector.Processor
instance. |
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() |
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.
Parameters | |
---|---|
frame |
Frame
|
Returns | |
---|---|
SparseArray<T> |
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. |
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 | |
---|---|
boolean |
true if the detector is operational, false if the dependency download is in progress |
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.
Parameters | |
---|---|
frame |
Frame
|
Shuts down the detector, releasing any underlying resources.
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 |
int :
tracking ID to become the focus for future detections. This is a mapping ID as
returned from detect(Frame) or received from getDetectedItems() .
|
Returns | |
---|---|
boolean |
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.
Parameters | |
---|---|
processor |
Processor
|