Skip to content

Commit

Permalink
[sfmData] imageInfo: Use "ImageSensorEffectiveWidth" if it exists in …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
cbentejac committed Jan 12, 2024
1 parent 3e4dff1 commit f0c4d25
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions src/aliceVision/sfmData/imageInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,26 @@ int ImageInfo::getSensorSize(const std::vector<sensorDB::Datasheet>& 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);

Expand Down Expand Up @@ -317,22 +332,6 @@ int ImageInfo::getSensorSize(const std::vector<sensorDB::Datasheet>& 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)
{
Expand Down

0 comments on commit f0c4d25

Please sign in to comment.