Camera

public class Camera

Provides information about the camera that is used to capture images. The Camera is a long-lived object and the properties of Camera are updated every time Session.update() is called.

Protected Constructors

Camera()
(FOR TESTING) Constructs a new instance for use as a mock.

Public Methods

boolean
equals(Object obj)
Indicates whether some other object is a Camera referencing the same logical camera as this one.
Pose
getDisplayOrientedPose()
Returns the pose of the user's device in the world coordinate space at the time of capture of the current camera texture.
CameraIntrinsics
getImageIntrinsics()
Returns the unrotated camera intrinsics for the CPU image.
Pose
getPose()
Returns the pose of the user's device in the world coordinate space at the time of capture of the current camera texture.
void
getProjectionMatrix(float[] dest, int offset, float near, float far)
Returns a projection matrix for rendering virtual content on top of the camera image.
CameraIntrinsics
getTextureIntrinsics()
Returns the unrotated camera intrinsics for the GPU texture.
TrackingState
getTrackingState()
Gets the current state of the pose of this camera.
void
getViewMatrix(float[] viewMatrix, int offset)
Returns the view matrix for the camera for this frame.
int
hashCode()
Returns a hash code value for the object.

Inherited Methods

Protected Constructors

protected Camera ()

(FOR TESTING) Constructs a new instance for use as a mock. Calling any base method implementation on this instance (including even equals(Object) and hashCode()) may return unexpected results, throw an exception, or even crash.

To obtain a Camera normally, use getCamera().

Public Methods

public boolean equals (Object obj)

Indicates whether some other object is a Camera referencing the same logical camera as this one.

Parameters
obj the reference object with which to compare.
Returns
  • true if this object is the same as the obj argument; false otherwise.

public Pose getDisplayOrientedPose ()

Returns the pose of the user's device in the world coordinate space at the time of capture of the current camera texture. The position of the pose is located at the device's camera, while the orientation approximately matches the orientation of the display (considering display rotation), using OpenGL camera conventions (+X right, +Y up, -Z in the direction the camera is looking).

public CameraIntrinsics getImageIntrinsics ()

Returns the unrotated camera intrinsics for the CPU image.

public Pose getPose ()

Returns the pose of the user's device in the world coordinate space at the time of capture of the current camera texture. The position and orientation of the pose follow the device's physical camera (they are not affected by display orientation). However, due to a bug the resulting pose is rotated around the Z axis by a multiple of 90° to (approximately) align the axes with those of the Android Sensor Coordinate System.

This bug will be fixed in an upcoming version of ARCore. Existing applications will continue to see the behavior of the ARCore SDK version that was compiled with the app. Until then, a pose aligned with the image sensor can be computed using the following code:

static Pose deviceToPhysical;
 // Can be done once after camera permission is granted.
 CameraManager cm = getSystemService(CameraManager.class);
 int sensorOrientation = Arrays.stream(cm.getCameraIdList()).map((id) -> {
   try {
     if (cm.getCameraCharacteristics(id).get(CameraCharacteristics.LENS_FACING) ==
             CameraMetadata.LENS_FACING_BACK) {
       return cm.getCameraCharacteristics(id).get(CameraCharacteristics.SENSOR_ORIENTATION);
     }
   } catch (CameraAccessException e) {
     throw new RuntimeException(e);
   }
   return -1;
 }).filter((orientation) -> orientation != -1).findFirst().orElse(0);
 deviceToPhysical = Pose.makeInterpolated(
         Pose.IDENTITY,
         Pose.makeRotation(0, 0, -(float)Math.sqrt(0.5), (float)Math.sqrt(0.5)),
         sensorOrientation / 90);
 // Per frame.
 Pose physicalCameraPose = camera.getPose().compose(deviceToPhysical);
 

Note: This pose is only useful when getTrackingState() returns TRACKING and otherwise should not be used.

public void getProjectionMatrix (float[] dest, int offset, float near, float far)

Returns a projection matrix for rendering virtual content on top of the camera image. Note that the projection matrix reflects the current display geometry and display rotation.

Parameters
dest storage for at least 16 floats representing a 4x4 matrix in column major order
offset the offset in dest at which to begin writing the matrix (often 0)
near specifies the near clip plane, in meters
far specifies the far clip plane, in meters

public CameraIntrinsics getTextureIntrinsics ()

Returns the unrotated camera intrinsics for the GPU texture.

public TrackingState getTrackingState ()

Gets the current state of the pose of this camera. If this state is anything other than TRACKING the pose should not be considered useful.

public void getViewMatrix (float[] viewMatrix, int offset)

Returns the view matrix for the camera for this frame. Note that the view matrix incorporates the display orientation. This is equivalent to: camera.getDisplayOrientedPose().inverse().asMatrix()

Parameters
viewMatrix storage for at least 16 floats representing a 4x4 matrix in column major order
offset the offset in viewMatrix at which to begin writing the matrix

public int hashCode ()

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by HashMap.

Returns
  • a hash code value for this object.
See Also

Send feedback about...