public class

CameraSource

extends Object
java.lang.Object
   ↳ com.google.android.gms.vision.CameraSource

Class Overview

Manages the camera in conjunction with an underlying Detector. 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 makes a best effort to manage processing on preview frames as fast as possible, while at the same time minimizing lag. As such, frames may be dropped if the detector is unable to keep up with the rate of frames generated by the camera. You should use setRequestedFps(float) to specify a frame rate that works well with the capabilities of the camera hardware and the detector options that you have selected. If CPU utilization is higher than you'd like, then you may want to consider reducing FPS. If the camera preview or detector results are too "jerky", then you may want to consider increasing FPS.

The following Android permission is required to use the camera:

  • android.permissions.CAMERA

Summary

Nested Classes
class CameraSource.Builder Builder for configuring and creating an associated camera source. 
interface CameraSource.PictureCallback Callback interface used to supply image data from a photo capture. 
interface CameraSource.ShutterCallback Callback interface used to signal the moment of actual image capture. 
Constants
int CAMERA_FACING_BACK
int CAMERA_FACING_FRONT
Public Methods
int getCameraFacing()
Returns the selected camera; one of CAMERA_FACING_BACK or CAMERA_FACING_FRONT.
Size getPreviewSize()
Returns the preview size that is currently in use by the underlying camera.
void release()
Stops the camera and releases the resources of the camera and underlying detector.
CameraSource start(SurfaceHolder surfaceHolder)
Opens the camera and starts sending preview frames to the underlying detector.
CameraSource start()
Opens the camera and starts sending preview frames to the underlying detector.
void stop()
Closes the camera and stops sending frames to the underlying frame detector.
void takePicture(CameraSource.ShutterCallback shutter, CameraSource.PictureCallback jpeg)
Initiates taking a picture, which happens asynchronously.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final int CAMERA_FACING_BACK

Constant Value: 0 (0x00000000)

public static final int CAMERA_FACING_FRONT

Constant Value: 1 (0x00000001)

Public Methods

public int getCameraFacing ()

Returns the selected camera; one of CAMERA_FACING_BACK or CAMERA_FACING_FRONT.

Returns
int

public Size getPreviewSize ()

Returns the preview size that is currently in use by the underlying camera.

Returns
Size

public void release ()

Stops the camera and releases the resources of the camera and underlying detector.

public CameraSource start (SurfaceHolder surfaceHolder)

Opens the camera and starts sending preview frames to the underlying detector. The supplied surface holder is used for the preview so frames can be displayed to the user.

Parameters
surfaceHolder SurfaceHolder: the surface holder to use for the preview frames
Returns
CameraSource
Throws
IOException if the supplied surface holder could not be used as the preview display

public CameraSource start ()

Opens the camera and starts sending preview frames to the underlying detector. The preview frames are not displayed.

Returns
CameraSource
Throws
IOException if the camera's preview texture or display could not be initialized

public void stop ()

Closes the camera and stops sending frames to the underlying frame detector.

This camera source may be restarted again by calling start() or start(SurfaceHolder).

Call release() instead to completely shut down this camera source and release the resources of the underlying detector.

public void takePicture (CameraSource.ShutterCallback shutter, CameraSource.PictureCallback jpeg)

Initiates taking a picture, which happens asynchronously. The camera source should have been activated previously with start() or start(SurfaceHolder). The camera preview is suspended while the picture is being taken, but will resume once picture taking is done.

Parameters
shutter CameraSource.ShutterCallback: the callback for image capture moment, or null
jpeg CameraSource.PictureCallback: the callback for JPEG image data, or null