can anyone know how to get sensor size of camera in android device ?
Thanks
It's easy to get width and height of the sensor of the camera with Camera1 Api too. Get horizontal and vertical angle of views and focal length and the rest is little trigonometry.
Camera.Parameters params = mCamera.getParameters();
focalLength = params.getFocalLength();
horizontalViewAngle = params.getHorizontalViewAngle();
verticalViewAngle = params.getVerticalViewAngle();
A = Angle of view, l = focal length, h = sensor height/2 => tan(A/2) = h/l
For my device with focal length 1.15 mm and horizontal angle of view 54.8 degrees:
Sensor width = tan(54.8/2)*2*1.15 = 1.19mm
This value is same with what i get using method DomTomCat posted.
It is possible as of API level 21. From the documentation (https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics.html#SENSOR_INFO_PHYSICAL_SIZE):
public static final Key SENSOR_INFO_PHYSICAL_SIZE
The physical dimensions of the full pixel array. [...]
Units: Millimeters
I use this kind of code. Beware, there might be more than just one camera:
import android.hardware.camera2.CameraAccessException;
import android.hardware.camera2.CameraCharacteristics;
import android.hardware.camera2.CameraManager;
private SizeF getCameraResolution(int camNum)
{
SizeF size = new SizeF(0,0);
CameraManager manager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);
try {
String[] cameraIds = manager.getCameraIdList();
if (cameraIds.length > camNum) {
CameraCharacteristics character = manager.getCameraCharacteristics(cameraIds[camNum]);
size = character.get(CameraCharacteristics.SENSOR_INFO_PHYSICAL_SIZE);
}
}
catch (CameraAccessException e)
{
Log.e("YourLogString", e.getMessage(), e);
}
return size;
}
Note that Exception CameraAccessException
needs to be caught.
Don't forget to add <uses-sdk android:minSdkVersion="21" />
to your manifest.