Created
July 24, 2019 05:59
-
-
Save claireliu14/28da8eb92b8f1f9f563a65771e7db99b to your computer and use it in GitHub Desktop.
Calculus FOV ( Field of View ) of ARCore camera
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public void onUpdate(FrameTime frameTime) { | |
Log.e(TAG, "Elephant rotation angle: " + rotationAngle); | |
// from arcore | |
try { | |
Frame frame = arFragment.getArSceneView().getSession().update(); | |
Camera camera = frame.getCamera(); | |
CameraIntrinsics intrinsics = camera.getImageIntrinsics(); | |
float focalLenght = intrinsics.getFocalLength()[0]; | |
int[] size = intrinsics.getImageDimensions(); | |
int w = size[0]; | |
int h = size[1]; | |
double fovW = Math.toDegrees(2 * Math.atan(w / (focalLenght * 2.0f))); | |
double fovH = Math.toDegrees(2 * Math.atan(h / (focalLenght * 2.0f))); | |
Log.e(TAG, String.format("ARCore - fovW: %f, fovH: %f", fovW, fovH)); | |
} catch (CameraNotAvailableException e) { | |
e.printStackTrace(); | |
} | |
// from camera2 api | |
try { | |
String cameraId = arFragment.getArSceneView().getSession().getCameraConfig().getCameraId(); | |
CameraManager cameraManager = (CameraManager) getSystemService(Context.CAMERA_SERVICE); | |
CameraCharacteristics cameraCharacteristics = cameraManager.getCameraCharacteristics(cameraId); | |
float[] maxFocus = cameraCharacteristics.get(CameraCharacteristics.LENS_INFO_AVAILABLE_FOCAL_LENGTHS); | |
SizeF size = cameraCharacteristics.get(CameraCharacteristics.SENSOR_INFO_PHYSICAL_SIZE); | |
float h = size.getHeight(); | |
float w = size.getWidth(); | |
double fovW = Math.toDegrees(2 * Math.atan(w / (maxFocus[0] * 2.0f))); | |
double fovH = Math.toDegrees(2 * Math.atan(h / (maxFocus[0] * 2.0f))); | |
Log.e(TAG, String.format("Camera2 - fovW: %f, fovH: %f", fovW, fovH)); | |
} catch (CameraAccessException e) { | |
e.printStackTrace(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Reference