Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How reliable is Android camera2 CameraCharacteristics API for sensor size?

I'm trying to get/compute the FOV for devices's cameras using camera2 API my code at the bottom).

On my attempt on a Galaxy S7 :

  • the given sensor size is 3.2mm x 2.4mm (using SENSOR_INFO_PHYSICAL_SIZE).
  • In this case, my computed HFOV is 41.7° (focal length given is 4.2mm) which I proved wrong by experimentation.
  • Various spec doc mention a 1/2.5" sensor size (5.76mm x 4.29mm according to wikipedia) - which would give me a HFOV of 68.9°, closer to my experiments.
  • the values in CameraCharacteristics seem wrong.

The same queries and experiments on a Samsung Galaxy A3-2016 are more conclusive, the calculated HFOV seems to match the experimental one.

Has anyone experience or data to share about the reliability of CameraCharacteristics readings ?


The code I used to query CameraCharacteristics ::

CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraID);
if (characteristics.get(CameraCharacteristics.LENS_FACING) == CameraCharacteristics.LENS_FACING_FRONT)
    continue;

int support = characteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL);
if( support == CameraMetadata.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY )
    Log.d("mr", "Camera " + cameraID + " has LEGACY Camera2 support");
else if( support == CameraMetadata.INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED )
    Log.d("mr", "Camera " + cameraID + " has LIMITED Camera2 support");
else if( support == CameraMetadata.INFO_SUPPORTED_HARDWARE_LEVEL_FULL )
    Log.d("mr", "Camera " + cameraID + " has FULL Camera2 support");
else
    Log.d("mr", "Camera " + cameraID + " has unknown Camera2 support?!");

// voir http://myandroidarchive.tistory.com/5 pour le query android
// voir http://paulbourke.net/miscellaneous/lens/ pour les maths
// include every focal length supported by the camera device, in ascending order.
float[] focalLengths = characteristics.get(CameraCharacteristics.LENS_INFO_AVAILABLE_FOCAL_LENGTHS);
SizeF sensorSize = characteristics.get(CameraCharacteristics.SENSOR_INFO_PHYSICAL_SIZE);

float w = 0.5f * sensorSize.getWidth();
float h = 0.5f * sensorSize.getHeight();
Log.d("mr", "Camera " + cameraID + " has sensorSize == " + Float.toString(2.0f*w) + ", " + Float.toString(2.0f*h));
for (int focusId=0; focusId<focalLengths.length; focusId++) {
    float focalLength = focalLengths[focusId];
    float horizonalAngle = (float) Math.toDegrees(2 * Math.atan(w / focalLength));
    float verticalAngle = (float) Math.toDegrees(2 * Math.atan(h / focalLength));
    Log.d("mr", "Camera " + cameraID + "/f" + focusId + " has focalLength == " + Float.toString(focalLength));
    Log.d("mr", "  * horizonalAngle == " + Float.toString(horizonalAngle));
    Log.d("mr", "  * verticalAngle == " + Float.toString(verticalAngle));
}
like image 965
rotoglup Avatar asked Nov 09 '16 16:11

rotoglup


People also ask

Is Camera2 deprecated?

camera2 API for new applications. This class was deprecated in API level 21. We recommend using the new android.

What is the use of Camera2 API?

Camera2 is the latest low-level Android camera package and replaces the deprecated Camera class. Camera2 provides in-depth controls for complex use cases, but requires you to manage device-specific configurations. You can read about specific Camera2 classes and functions in the reference documentation.


1 Answers

Developer of Scanbot here (aka I worked with camera enough).

From my experience nothing about Camera API can be reliable mostly because this API is a relatively thin layer upon hardware and vendor specific camera driver. In other words, output of API will depend on what vendor decided to put there and is not (unlike the rest of the Android SDK) governed by Google.

like image 140
Dmitry Zaytsev Avatar answered Oct 03 '22 14:10

Dmitry Zaytsev