ObjectDetection
Stay organized with collections
Save and categorize content based on your preferences.
Entry point to get an ObjectDetector
for finding DetectedObject
s
in a supplied image.
An ObjectDetector
is created via getClient(ObjectDetectorOptionsBase)
.
Example:
ObjectDetector objectDetector = ObjectDetection.getClient(options);
To perform object detection in an image, you first need to create an instance of InputImage
from a Bitmap
, ByteBuffer
, etc. See InputImage
documentation for more details. For example, the code below creates an InputImage
from a Bitmap
.
InputImage image = InputImage.fromBitmap(bitmap, rotationDegrees);
Then the code below can detect objects in the supplied InputImage
.
Task<List<DetectedObject>> task = objectDetector.process(image);
task.addOnSuccessListener(...).addOnFailureListener(...);
Inherited Method Summary
From class java.lang.Object
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License
, and code samples are licensed under the Apache 2.0 License
. For details, see the Google Developers Site Policies
. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-10-31 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-10-31 UTC."],[[["\u003cp\u003e\u003ccode\u003eObjectDetection\u003c/code\u003e is the entry point for object detection in images using ML Kit.\u003c/p\u003e\n"],["\u003cp\u003eYou create an \u003ccode\u003eObjectDetector\u003c/code\u003e instance using \u003ccode\u003eObjectDetection.getClient()\u003c/code\u003e with specified options.\u003c/p\u003e\n"],["\u003cp\u003eObject detection is performed by processing an \u003ccode\u003eInputImage\u003c/code\u003e with the \u003ccode\u003eObjectDetector\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eRemember to call \u003ccode\u003eObjectDetector.close()\u003c/code\u003e to release resources when the detector is no longer needed.\u003c/p\u003e\n"]]],[],null,["# ObjectDetection\n\npublic class **ObjectDetection** extends [Object](//developer.android.com/reference/java/lang/Object.html) \nEntry point to get an [ObjectDetector](/android/reference/com/google/mlkit/vision/objects/ObjectDetector)\nfor finding [DetectedObject](/android/reference/com/google/mlkit/vision/objects/DetectedObject)s\nin a supplied image.\n\nAn [ObjectDetector](/android/reference/com/google/mlkit/vision/objects/ObjectDetector)\nis created via [getClient(ObjectDetectorOptionsBase)](/android/reference/com/google/mlkit/vision/objects/ObjectDetection#getClient(com.google.mlkit.vision.objects.ObjectDetectorOptionsBase)).\n\nExample: \n\n ObjectDetector objectDetector = ObjectDetection.getClient(options); \n\nTo perform object detection in an image, you first need to create an instance of\n[InputImage](/android/reference/com/google/mlkit/vision/common/InputImage)\nfrom a [Bitmap](//developer.android.com/reference/android/graphics/Bitmap.html),\n[ByteBuffer](//developer.android.com/reference/java/nio/ByteBuffer.html), etc. See\n[InputImage](/android/reference/com/google/mlkit/vision/common/InputImage)\ndocumentation for more details. For example, the code below creates an [InputImage](/android/reference/com/google/mlkit/vision/common/InputImage)\nfrom a [Bitmap](//developer.android.com/reference/android/graphics/Bitmap.html). \n\n InputImage image = InputImage.fromBitmap(bitmap, rotationDegrees); \n\nThen the code below can detect objects in the supplied [InputImage](/android/reference/com/google/mlkit/vision/common/InputImage). \n\n Task\u003cList\u003cDetectedObject\u003e\u003e task = objectDetector.process(image);\n task.addOnSuccessListener(...).addOnFailureListener(...); \n\n### Public Method Summary\n\n|--------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| static [ObjectDetector](/android/reference/com/google/mlkit/vision/objects/ObjectDetector) | [getClient](/android/reference/com/google/mlkit/vision/objects/ObjectDetection#getClient(com.google.mlkit.vision.objects.ObjectDetectorOptionsBase))([ObjectDetectorOptionsBase](/android/reference/com/google/mlkit/vision/objects/ObjectDetectorOptionsBase) options) Gets a new instance of [ObjectDetector](/android/reference/com/google/mlkit/vision/objects/ObjectDetector) that can detect objects in a supplied image with the given options. |\n\n### Inherited Method Summary\n\nFrom class java.lang.Object \n\n|----------------------------------------------------------------------------|--------------------------------------------------------------------------------|\n| [Object](//developer.android.com/reference/java/lang/Object.html) | clone() |\n| boolean | equals([Object](//developer.android.com/reference/java/lang/Object.html) arg0) |\n| void | finalize() |\n| final [Class](//developer.android.com/reference/java/lang/Class.html)\\\u003c?\\\u003e | getClass() |\n| int | hashCode() |\n| final void | notify() |\n| final void | notifyAll() |\n| [String](//developer.android.com/reference/java/lang/String.html) | toString() |\n| final void | wait(long arg0, int arg1) |\n| final void | wait(long arg0) |\n| final void | wait() |\n\nPublic Methods\n--------------\n\n#### public static [ObjectDetector](/android/reference/com/google/mlkit/vision/objects/ObjectDetector)\n**getClient** ([ObjectDetectorOptionsBase](/android/reference/com/google/mlkit/vision/objects/ObjectDetectorOptionsBase) options)\n\nGets a new instance of [ObjectDetector](/android/reference/com/google/mlkit/vision/objects/ObjectDetector)\nthat can detect objects in a supplied image with the given options.\n\nTo release the resources associated with an [ObjectDetector](/android/reference/com/google/mlkit/vision/objects/ObjectDetector),\nyou need to ensure that [ObjectDetector.close()](/android/reference/com/google/mlkit/vision/objects/ObjectDetector#close())\nis called on the resulting [ObjectDetector](/android/reference/com/google/mlkit/vision/objects/ObjectDetector)\ninstance once it will no longer be used. \n\n##### Parameters\n\n| options | the options for the object detector. It should be one of the concrete options like [ObjectDetectorOptions](/android/reference/com/google/mlkit/vision/objects/defaults/ObjectDetectorOptions) or [CustomObjectDetectorOptions](/android/reference/com/google/mlkit/vision/objects/custom/CustomObjectDetectorOptions). |\n|---------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|"]]