Cristian Almstrand
Cristian Almstrand

Reputation: 713

How to calculate field of view in arcore?

Is there a property or method that can be used to access the field of view ("FoV", "angle of view") of the camera when working with arcore?

From some experimentation it appears the FoV is typically about 60 degrees, but presumably this will vary depending on the device hardware.

If it cannot be directly accessed, is there a way to instead calculate the FoV angle from any of the Camera object properties e.g. the view matrix?

Upvotes: 1

Views: 1474

Answers (2)

Atul Vasudev A
Atul Vasudev A

Reputation: 463

Its available now within CameraIntrinsics class as getFocalLength()

The output is focal length in pixels which can be converted to degrees if image size is known.

Upvotes: 0

eugene.ltv
eugene.ltv

Reputation: 31

ARCore library v1.8.0 doesn't return FoV value. Instead you can calculate it using Camera parameters:

val frame = session.update()
val camera = frame.camera
val imageIntrinsics = camera.imageIntrinsics

val focalLength = imageIntrinsics.focalLength[0]
val size = imageIntrinsics.imageDimensions
val w = size[0]
val h = size[1]

val fovW = Math.toDegrees(2 * Math.atan(w / (focalLength * 2.0)))
val fovH = Math.toDegrees(2 * Math.atan(h / (focalLength * 2.0)))

Another solution with Camera2 API:

val cameraId = session.cameraConfig.cameraId

val cameraManager = context.getSystemService(Context.CAMERA_SERVICE) as CameraManager
val characteristics = cameraManager.getCameraCharacteristics(cameraId)

val maxFocus = characteristics.get(CameraCharacteristics.LENS_INFO_AVAILABLE_FOCAL_LENGTHS)
val size = characteristics.get(CameraCharacteristics.SENSOR_INFO_PHYSICAL_SIZE)
val w = size.width
val h = size.height

val fovW = Math.toDegrees(2 * Math.atan(w / (maxFocus[0] * 2.0)))
val fovH = Math.toDegrees(2 * Math.atan(h / (maxFocus[0] * 2.0)))

Upvotes: 3

Related Questions