如何计算arcore中的视场?

时间:2018-10-16 05:47:43

标签: android arcore

使用arcore时,是否可以使用属性或方法访问相机的视野(“ FoV”,“视角”)?

从一些实验来看,FoV通常约为60度,但是大概会因设备硬件而异。

如果无法直接访问它,则有一种方法可以从任何Camera对象属性中计算出FoV角度,例如视图矩阵?

1 个答案:

答案 0 :(得分:2)

ARCore v1.8.0 不返回FoV值。相反,您可以使用Camera参数进行计算:

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)))

使用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)))