From f0c4d255b92fe8f3ddb0b806fdca2f045f244d25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Candice=20Bent=C3=A9jac?= Date: Fri, 12 Jan 2024 17:06:13 +0100 Subject: [PATCH] [sfmData] imageInfo: Use "ImageSensorEffectiveWidth" if it exists in metadata When trying to find the focal length in the metadata, if the "ImageSensorEffectiveWidth" key exists, it should be used first to set the sensor width without having to look for any other metadata key as it is the most reliable one. --- src/aliceVision/sfmData/imageInfo.cpp | 33 +++++++++++++-------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/src/aliceVision/sfmData/imageInfo.cpp b/src/aliceVision/sfmData/imageInfo.cpp index 0d4e9d15c3..4d32d7c870 100644 --- a/src/aliceVision/sfmData/imageInfo.cpp +++ b/src/aliceVision/sfmData/imageInfo.cpp @@ -246,11 +246,26 @@ int ImageInfo::getSensorSize(const std::vector& sensorDatab } } + // If available, effective sensor width and height are provided in µm (Sony) + const double effectiveSensorWidth = getDoubleMetadata({"ImageSensorEffectiveWidth"}); + const double effectiveSensorHeight = getDoubleMetadata({"ImageSensorEffectiveHeight"}); + // try to find / compute with 'FocalLengthIn35mmFilm' metadata const bool hasFocalIn35mmMetadata = hasDigitMetadata({"Exif:FocalLengthIn35mmFilm", "FocalLengthIn35mmFilm", "LensZoom35mmStillCameraEquivalent"}); - if (hasFocalIn35mmMetadata) + // If no sensor width has been found or computed yet and the effective sensor width is available, then use it + const bool effectiveSensorSizeApplied = effectiveSensorWidth != -1.0 && sensorWidth == -1.0; + if (effectiveSensorSizeApplied) + { + sensorWidth = effectiveSensorWidth / 1000.0; + if (effectiveSensorHeight != -1.0) + { + sensorHeight = effectiveSensorHeight / 1000.0; + } + sensorWidthSource = ESensorWidthSource::FROM_METADATA_ESTIMATION; + } + else if (hasFocalIn35mmMetadata) { const double diag24x36 = std::sqrt(36.0 * 36.0 + 24.0 * 24.0); @@ -317,22 +332,6 @@ int ImageInfo::getSensorSize(const std::vector& sensorDatab } } - // If available, effective sensor width and height are provided in µm (Sony) - const double effectiveSensorWidth = getDoubleMetadata({"ImageSensorEffectiveWidth"}); - const double effectiveSensorHeight = getDoubleMetadata({"ImageSensorEffectiveHeight "}); - - // If no sensor width has been found or computed yet and the effective sensor width is available, then use it - const bool effectiveSensorSizeApplied = effectiveSensorWidth != -1.0 && sensorWidth == -1.0; - if (effectiveSensorSizeApplied) - { - sensorWidth = effectiveSensorWidth / 1000.0; - if (effectiveSensorHeight != -1.0) - { - sensorHeight = effectiveSensorHeight / 1000.0; - } - sensorWidthSource = ESensorWidthSource::FROM_METADATA_ESTIMATION; - } - // error handling if (sensorWidth == -1.0) {