-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Description
Use case
When a device is used with multiple back camera's. It would be handy to know the focal length of each camera.
That way a user interface can be implemented that shows the appropriate icons for each camera.
Ex:
Proposal
A new attribute to the CameraDescription class "focalLength". Used like this:
cameras = await availableCameras();
for (CameraDescription c in cameras) {
print(c.focalLength);
}
Android: camera2 supports focalLength
https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics
IOS: AvFoundation doesn't support a focallength parameter
A distinction between ultrawide, wide and telephoto lens would also be a huge step forward.
https://developer.apple.com/documentation/avfoundation/avcapturedevice/devicetype
Otherwise the videoFieldOfView parameter could be used and converted
https://developer.apple.com/documentation/avfoundation/avcapturedeviceformat/1624569-videofieldofview
func get35mmEquivalentFocalLength(format : AVCaptureDevice.Format) -> Float {
// get reported field of view. Documentation says this is the horizontal field of view
var fov = format.videoFieldOfView
// convert to radians
fov *= Float.pi/180.0
// angle and opposite of right angle triangle are half the fov and half the width of
// 35mm film (ie 18mm). The adjacent value of the right angle triangle is the equivalent
// focal length. Using some right angle triangle math you can work out focal length
let focalLen = 18 / tan(fov/2)
return focalLen
}
