Closed seadeep42 closed 1 month ago
Guten Tag, Hans here.
[!NOTE] New features, bugfixes, updates and other improvements are all handled mostly by
@mrousavy
in his free time. To support@mrousavy
, please consider π sponsoring him on GitHub π. Sponsored issues will be prioritized.
No, there is not at the moment.
You can create a feature request for this - or even better - a PR to implement this, if you want :)
On iOS we have lensPosition
- not sure if this is actually what we want:
A lens position value doesnβt correspond to an exact physical distance, nor does it represent a consistent focus distance from device to device.
It only exposes a value from 0.0
to 1.0
, no exact millimeters. So I don't think the underlying iOS camera API supports getting the focal length.
Why do you need focal length anyways?
I found this code somewhere in a gist:
func getFocalLengthInMillimeters(captureDevice: AVCaptureDevice) -> Float? {
guard let format = captureDevice.activeFormat else {
return nil
}
// Get the intrinsic matrix, which provides focal length in pixels
let dimensions = CMVideoFormatDescriptionGetDimensions(format.formatDescription)
let sensorWidth = format.sensorDimensions.width
let sensorHeight = format.sensorDimensions.height
let intrinsicMatrix = format.formatDescription.intrinsicMatrix
// Calculate the focal length in millimeters
let focalLengthInPixels = intrinsicMatrix[0][0] // This is the fx value
let sensorPhysicalWidth = format.sensorPhysicalSize.width
let sensorPhysicalHeight = format.sensorPhysicalSize.height
let focalLengthInMillimeters = (focalLengthInPixels / Float(dimensions.width)) * Float(sensorPhysicalWidth)
return focalLengthInMillimeters
}
But it looks very hacky and depends on activeFormat, I don't think this can work reliably in getAvailableCameraDevices()
.
This might only work if we pass it alongside with Frame
, but I kinda want to avoid that since the intrinsic matrix and focal length has nothing to do with a Frame, but more with a Camera device - it's contextually in the wrong place.
Also maybe related to https://github.com/mrousavy/react-native-vision-camera/issues/3032
Question
I'm using the front camera with a frame processor. Is there a way to get the focal length of the image either as a camera parameter or a property of the frame?
What I tried
No response
VisionCamera Version
4.5.0
Additional information