CameraXSource
Stay organized with collections
Save and categorize content based on your preferences.
Manages the camera in conjunction with an underlying Detector
and
DetectionTaskCallback
.
This receives preview frames from the camera at a specified rate, sending those frames to the
detector as fast as it is able to process those frames.
This camera source is using CameraX APIs internally.
The following Android permission is required to use the camera:
- android.permissions.CAMERA
Public Constructor Summary
Public Method Summary
void |
close()
Closes the camera and releases the resources of the camera and underlying
detector.
|
int |
|
Size
|
getPreviewSize()
Returns the preview size that is currently in use by the underlying camera.
|
void |
start()
Opens the camera and starts sending preview frames to the underlying detector.
|
void |
stop()
Stops the camera and releases the resources of the camera.
|
Inherited Method Summary
From class java.lang.Object
Object
|
clone()
|
boolean |
|
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()
|
From interface androidx.lifecycle.LifecycleOwner
abstract Lifecycle |
getLifecycle()
|
Public Methods
public void close ()
Closes the camera and releases the resources of the camera and underlying
detector.
public int getCameraFacing ()
public Size getPreviewSize ()
Returns the preview size that is currently in use by the underlying camera. The
result could be null if the PreviewView has not been started.
public void start ()
Opens the camera and starts sending preview frames to the underlying detector.
public void stop ()
Stops the camera and releases the resources of the camera.
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\u003eCameraXSource\u003c/code\u003e manages camera interaction for ML Kit, processing preview frames with a detector.\u003c/p\u003e\n"],["\u003cp\u003eIt uses CameraX APIs and requires the \u003ccode\u003eandroid.permission.CAMERA\u003c/code\u003e permission.\u003c/p\u003e\n"],["\u003cp\u003eProvides methods to start/stop the camera, close resources, and get camera properties like facing and preview size.\u003c/p\u003e\n"],["\u003cp\u003eCan be configured using \u003ccode\u003eCameraSourceConfig\u003c/code\u003e and optionally display preview frames in a \u003ccode\u003ePreviewView\u003c/code\u003e.\u003c/p\u003e\n"]]],[],null,["public class **CameraXSource** extends [Object](//developer.android.com/reference/java/lang/Object.html) \nimplements LifecycleOwner \nManages the camera in conjunction with an underlying [Detector](/android/reference/com/google/mlkit/vision/interfaces/Detector) and\n[DetectionTaskCallback](/android/reference/com/google/mlkit/vision/camera/DetectionTaskCallback).\nThis receives preview frames from the camera at a specified rate, sending those frames to the\ndetector as fast as it is able to process those frames.\n\nThis camera source is using CameraX APIs internally.\n\nThe following Android permission is required to use the camera:\n\n- android.permissions.CAMERA \n\nPublic Constructor Summary\n\n|---|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| | [CameraXSource](/android/reference/com/google/mlkit/vision/camera/CameraXSource#CameraXSource(com.google.mlkit.vision.camera.CameraSourceConfig))([CameraSourceConfig](/android/reference/com/google/mlkit/vision/camera/CameraSourceConfig) cameraSourceConfig) Create a [CameraXSource](/android/reference/com/google/mlkit/vision/camera/CameraXSource) with given [CameraSourceConfig](/android/reference/com/google/mlkit/vision/camera/CameraSourceConfig). |\n| | [CameraXSource](/android/reference/com/google/mlkit/vision/camera/CameraXSource#CameraXSource(com.google.mlkit.vision.camera.CameraSourceConfig,%20androidx.camera.view.PreviewView))([CameraSourceConfig](/android/reference/com/google/mlkit/vision/camera/CameraSourceConfig) cameraSourceConfig, PreviewView previewView) Create a [CameraXSource](/android/reference/com/google/mlkit/vision/camera/CameraXSource) with given [CameraSourceConfig](/android/reference/com/google/mlkit/vision/camera/CameraSourceConfig) and a [PreviewView](/android/reference/androidx/camera/view/PreviewView) for the preview frames to be displayed to the user. |\n\nPublic Method Summary\n\n|------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| void | [close](/android/reference/com/google/mlkit/vision/camera/CameraXSource#close())() Closes the camera and releases the resources of the camera and underlying detector. |\n| int | [getCameraFacing](/android/reference/com/google/mlkit/vision/camera/CameraXSource#getCameraFacing())() Returns the selected camera; one of [CameraSourceConfig.CAMERA_FACING_BACK](/android/reference/com/google/mlkit/vision/camera/CameraSourceConfig#CAMERA_FACING_BACK) or [CameraSourceConfig.CAMERA_FACING_FRONT](/android/reference/com/google/mlkit/vision/camera/CameraSourceConfig#CAMERA_FACING_FRONT). |\n| [Size](//developer.android.com/reference/android/util/Size.html) | [getPreviewSize](/android/reference/com/google/mlkit/vision/camera/CameraXSource#getPreviewSize())() Returns the preview size that is currently in use by the underlying camera. |\n| void | [start](/android/reference/com/google/mlkit/vision/camera/CameraXSource#start())() Opens the camera and starts sending preview frames to the underlying detector. |\n| void | [stop](/android/reference/com/google/mlkit/vision/camera/CameraXSource#stop())() Stops the camera and releases the resources of the camera. |\n\nInherited Method Summary \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\nFrom interface androidx.lifecycle.LifecycleOwner \n\n|--------------------|----------------|\n| abstract Lifecycle | getLifecycle() |\n\nPublic Constructors \n\npublic **CameraXSource** ([CameraSourceConfig](/android/reference/com/google/mlkit/vision/camera/CameraSourceConfig) cameraSourceConfig) \nCreate a [CameraXSource](/android/reference/com/google/mlkit/vision/camera/CameraXSource)\nwith given [CameraSourceConfig](/android/reference/com/google/mlkit/vision/camera/CameraSourceConfig). \n\npublic **CameraXSource** ([CameraSourceConfig](/android/reference/com/google/mlkit/vision/camera/CameraSourceConfig) cameraSourceConfig, PreviewView previewView) \nCreate a [CameraXSource](/android/reference/com/google/mlkit/vision/camera/CameraXSource)\nwith given [CameraSourceConfig](/android/reference/com/google/mlkit/vision/camera/CameraSourceConfig)\nand a [PreviewView](/android/reference/androidx/camera/view/PreviewView) for\nthe preview frames to be displayed to the user.\n\nPublic Methods \n\npublic void **close** () \nCloses the camera and releases the resources of the camera and underlying\ndetector. \n\npublic int **getCameraFacing** () \nReturns the selected camera; one of [CameraSourceConfig.CAMERA_FACING_BACK](/android/reference/com/google/mlkit/vision/camera/CameraSourceConfig#CAMERA_FACING_BACK) or [CameraSourceConfig.CAMERA_FACING_FRONT](/android/reference/com/google/mlkit/vision/camera/CameraSourceConfig#CAMERA_FACING_FRONT). \n\npublic [Size](//developer.android.com/reference/android/util/Size.html) **getPreviewSize** () \nReturns the preview size that is currently in use by the underlying camera. The\nresult could be null if the PreviewView has not been started. \n\npublic void **start** () \nOpens the camera and starts sending preview frames to the underlying detector. \n\npublic void **stop** () \nStops the camera and releases the resources of the camera."]]