Add auto focal length for perspective in editor
If the focal length and/or crop factor for the camera-based perspective correction tool are not edited, they will be set using the focal length information found in the image metadata. This only applies to the editor (batch editor and CLI still default to 24 for the focal length and 1 for the crop factor).
This commit is contained in:
parent
65e76df279
commit
9a594474d9
@ -467,9 +467,10 @@ bool ImProcFunctions::transCoord (int W, int H, const std::vector<Coord2D> &src,
|
||||
double hpteta = fabs (hpalpha - rtengine::RT_PI / 2) < 3e-4 ? 0.0 : acos ((hpdeg > 0 ? 1.0 : -1.0) * sqrt ((-oH * oH * tan (hpalpha) * tan (hpalpha) + (hpdeg > 0 ? 1.0 : -1.0) * oH * tan (hpalpha) * sqrt (16 * maxRadius * maxRadius + oH * oH * tan (hpalpha) * tan (hpalpha))) / (maxRadius * maxRadius * 8)));
|
||||
double hpcospt = (hpdeg >= 0 ? 1.0 : -1.0) * cos (hpteta), hptanpt = tan (hpteta);
|
||||
// Camera-based.
|
||||
const double f = params->perspective.camera_focal_length *
|
||||
params->perspective.camera_crop_factor * (maxRadius / sqrt(18.0*18.0 +
|
||||
12.0*12.0));
|
||||
const double f =
|
||||
((params->perspective.camera_focal_length > 0) ? params->perspective.camera_focal_length : 24.0)
|
||||
* ((params->perspective.camera_crop_factor > 0) ? params->perspective.camera_crop_factor : 1.0)
|
||||
* (maxRadius / sqrt(18.0*18.0 + 12.0*12.0));
|
||||
const double p_camera_yaw = params->perspective.camera_yaw / 180.0 * rtengine::RT_PI;
|
||||
const double p_camera_pitch = params->perspective.camera_pitch / 180.0 * rtengine::RT_PI;
|
||||
const double p_camera_roll = params->perspective.camera_roll * rtengine::RT_PI_180;
|
||||
@ -1165,9 +1166,10 @@ void ImProcFunctions::transformGeneral(bool highQuality, Imagefloat *original, I
|
||||
const double hpcospt = (hpdeg >= 0 ? 1.0 : -1.0) * cos(hpteta);
|
||||
const double hptanpt = tan(hpteta);
|
||||
// Camera-based.
|
||||
const double f = params->perspective.camera_focal_length *
|
||||
params->perspective.camera_crop_factor * (maxRadius / sqrt(18.0*18.0 +
|
||||
12.0*12.0));
|
||||
const double f =
|
||||
((params->perspective.camera_focal_length > 0) ? params->perspective.camera_focal_length : 24.0)
|
||||
* ((params->perspective.camera_crop_factor > 0) ? params->perspective.camera_crop_factor : 1.0)
|
||||
* (maxRadius / sqrt(18.0*18.0 + 12.0*12.0));
|
||||
const double p_camera_yaw = params->perspective.camera_yaw / 180.0 * rtengine::RT_PI;
|
||||
const double p_camera_pitch = params->perspective.camera_pitch / 180.0 * rtengine::RT_PI;
|
||||
const double p_camera_roll = params->perspective.camera_roll * rtengine::RT_PI_180;
|
||||
|
@ -1854,8 +1854,8 @@ PerspectiveParams::PerspectiveParams() :
|
||||
method("simple"),
|
||||
horizontal(0.0),
|
||||
vertical(0.0),
|
||||
camera_crop_factor(1.0),
|
||||
camera_focal_length(24.0),
|
||||
camera_crop_factor(0.0),
|
||||
camera_focal_length(0.0),
|
||||
camera_pitch(0.0),
|
||||
camera_roll(0.0),
|
||||
camera_shift_horiz(0.0),
|
||||
|
@ -213,8 +213,7 @@ void PerspCorrection::read (const ProcParams* pp, const ParamsEdited* pedited)
|
||||
|
||||
horiz->setValue (pp->perspective.horizontal);
|
||||
vert->setValue (pp->perspective.vertical);
|
||||
camera_crop_factor->setValue (pp->perspective.camera_crop_factor);
|
||||
camera_focal_length->setValue (pp->perspective.camera_focal_length);
|
||||
setFocalLengthValue (pp, metadata);
|
||||
camera_pitch->setValue (pp->perspective.camera_pitch);
|
||||
camera_roll->setValue (pp->perspective.camera_roll);
|
||||
camera_shift_horiz->setValue (pp->perspective.camera_shift_horiz);
|
||||
@ -461,6 +460,11 @@ void PerspCorrection::setAdjusterBehavior (bool badd, bool camera_focal_length_a
|
||||
projection_yaw->setAddMode(projection_angle_add);
|
||||
}
|
||||
|
||||
void PerspCorrection::setMetadata (const rtengine::FramesMetaData* metadata)
|
||||
{
|
||||
this->metadata = metadata;
|
||||
}
|
||||
|
||||
void PerspCorrection::trimValues (rtengine::procparams::ProcParams* pp)
|
||||
{
|
||||
|
||||
@ -507,3 +511,49 @@ void PerspCorrection::setBatchMode (bool batchMode)
|
||||
|
||||
method->append (M("GENERAL_UNCHANGED"));
|
||||
}
|
||||
|
||||
void PerspCorrection::setFocalLengthValue (const ProcParams* pparams, const FramesMetaData* metadata)
|
||||
{
|
||||
const double pp_crop_factor = pparams->perspective.camera_crop_factor;
|
||||
const double pp_focal_length = pparams->perspective.camera_focal_length;
|
||||
double default_crop_factor = 1.0;
|
||||
double default_focal_length = 24.0;
|
||||
|
||||
// Defaults from metadata.
|
||||
if (metadata && (pp_crop_factor <= 0 || pp_focal_length <= 0)) {
|
||||
const double fl = metadata->getFocalLen();
|
||||
const double fl35 = metadata->getFocalLen35mm();
|
||||
|
||||
if (fl <= 0) {
|
||||
if (fl35 <= 0) {
|
||||
// No focal length data.
|
||||
} else {
|
||||
// 35mm focal length available.
|
||||
default_focal_length = fl35;
|
||||
}
|
||||
} else {
|
||||
if (fl35 <= 0) {
|
||||
// Focal length available.
|
||||
default_focal_length = fl;
|
||||
} else {
|
||||
// Focal length and 35mm equivalent available.
|
||||
default_focal_length = fl;
|
||||
default_crop_factor = fl35 / fl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Change value if those from the ProcParams are invalid.
|
||||
if (pp_crop_factor > 0) {
|
||||
camera_crop_factor->setValue(pparams->perspective.camera_crop_factor);
|
||||
} else {
|
||||
camera_crop_factor->setDefault(default_crop_factor);
|
||||
camera_crop_factor->setValue(default_crop_factor);
|
||||
}
|
||||
if (pp_focal_length > 0) {
|
||||
camera_focal_length->setValue(pparams->perspective.camera_focal_length);
|
||||
} else {
|
||||
camera_focal_length->setDefault(default_focal_length);
|
||||
camera_focal_length->setValue(default_focal_length);
|
||||
}
|
||||
}
|
||||
|
@ -53,6 +53,9 @@ protected:
|
||||
Adjuster* projection_shift_vert;
|
||||
Adjuster* projection_yaw;
|
||||
LensGeomListener* lens_geom_listener;
|
||||
const rtengine::FramesMetaData* metadata;
|
||||
|
||||
void setFocalLengthValue (const rtengine::procparams::ProcParams* pparams, const rtengine::FramesMetaData* metadata);
|
||||
|
||||
public:
|
||||
|
||||
@ -71,5 +74,6 @@ public:
|
||||
{
|
||||
lens_geom_listener = listener;
|
||||
}
|
||||
void setMetadata (const rtengine::FramesMetaData* metadata);
|
||||
void trimValues (rtengine::procparams::ProcParams* pp) override;
|
||||
};
|
||||
|
@ -615,6 +615,7 @@ void ToolPanelCoordinator::initImage (rtengine::StagedImageProcessor* ipc_, bool
|
||||
|
||||
icm->setRawMeta (raw, (const rtengine::FramesData*)pMetaData);
|
||||
lensProf->setRawMeta (raw, pMetaData);
|
||||
perspective->setMetadata (pMetaData);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user