Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting Focal Length in millimeters to pixels - Android

Tags:

android

In Android, I am currently accessing the camera's focal length by using getFocalLength() in Camera1. Camera2 is not an option.

I am trying to full fill the current calculation: focal_length_pix = focal_length_m * 1 (pix) / pixel_width_m.

Basically this converts the focal length from mm -> px. Now I know the focal_length_m variable but I am currently trying to figure out the pixel_width_m which is is the width of a pixel (on the sensor) in meters.

I am struggling to find a way to calculate the width of a pixel on the sensor. Any suggestions, ideas would be much appreciated.

like image 439
David Biga Avatar asked Mar 12 '23 20:03

David Biga


1 Answers

You are able to calculate the focal length in pixels by the following:

double focal_length_pix = (size.width * 0.5) / tan(horizontalAngleView * 0.5 * PI/180);

size derives from getPreviewSize()

like image 110
David Biga Avatar answered Mar 24 '23 00:03

David Biga