user7448105
user7448105

Reputation:

Camera Parameters - iPhone 7

Good evening folks of Stackoverflow,

I've been trying to find accurate data for calculating the focal parameter of CameraParams for quite some time but actively failed.

Here's what I got so far:

iPhone 7
Sensor width: 3.99mm
Focal length: 7.21mm
Random image: 400x400

Calculation:

focal(in pixel) = image width(in pixel)*focal(in mm)/sensor width(mm)

focal = 400 * 7.21 / 3.99

But that results to look very inaccurate. Is there something I'm missing?

Upvotes: 1

Views: 2948

Answers (1)

adamfowlerphoto
adamfowlerphoto

Reputation: 2751

This page (https://developer.apple.com/library/content/documentation/DeviceInformation/Reference/iOSDeviceCompatibility/Cameras/Cameras.html) gives you specs for each model of the iPhone camera.

You can also use the following code to get the spec for the camera when taking photos.

private func getCaptureDeviceSpec(_ videoDevice : AVCaptureDevice?) {
    if let deviceFormats = videoDevice?.formats {
        var width : Float = 0
        var height : Float = 0
        var fov : Float = 0
        for format in deviceFormats {
            if let deviceFormat = (format as? AVCaptureDeviceFormat) {
                let dim = deviceFormat.highResolutionStillImageDimensions
                if width < Float(dim.width) && height < Float(dim.height) {
                    width = Float(dim.width)
                    height = Float(dim.height)
                    fov = deviceFormat.videoFieldOfView
                }
            }
        }
        cameraSpec.width = width
        cameraSpec.height = height
        cameraSpec.fov = fov
    }
}

Upvotes: 1

Related Questions