Skip to content

[Camera]: get focal length of camera #119908

@kareldb

Description

@kareldb

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:

191372954-b30ebe8e-f417-4f7e-84f9-56267e006387

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
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projectc: new featureNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to Flutterp: cameraThe camera pluginpackageflutter/packages repository. See also p: labels.team-ecosystemOwned by Ecosystem teamtriaged-ecosystemTriaged by Ecosystem team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions