Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ LensDistortPlugin::LensDistortPlugin( OfxImageEffectHandle handle )
_coef1 = fetchDoubleParam ( kParamCoef1 );
_coef2 = fetchDoubleParam ( kParamCoef2 );
_coef3 = fetchDoubleParam ( kParamCoef3 );
_coef4 = fetchDoubleParam ( kParamCoef4 );
_squeeze = fetchDoubleParam ( kParamSqueeze );
_asymmetric = fetchDouble2DParam ( kParamAsymmetric );
_center = fetchDouble2DParam ( kParamCenter );
Expand Down Expand Up @@ -82,24 +83,35 @@ void LensDistortPlugin::changedParam( const OFX::InstanceChangedArgs& args, cons
case eParamLensTypeBrown1:
_coef2 -> setIsSecretAndDisabled( true );
_coef3 -> setIsSecretAndDisabled( true );
_coef4 ->setIsSecretAndDisabled( true );
_squeeze -> setIsSecretAndDisabled( true );
_asymmetric -> setIsSecretAndDisabled( true );
break;
case eParamLensTypeBrown3:
_coef2 -> setIsSecretAndDisabled( false );
_coef3 -> setIsSecretAndDisabled( false );
_coef4 ->setIsSecretAndDisabled( true );
_squeeze -> setIsSecretAndDisabled( true );
_asymmetric -> setIsSecretAndDisabled( true );
break;
case eParamLensTypePTLens:
_coef2 -> setIsSecretAndDisabled( false );
_coef3 -> setIsSecretAndDisabled( false );
_coef4 ->setIsSecretAndDisabled( true );
_squeeze -> setIsSecretAndDisabled( true );
_asymmetric -> setIsSecretAndDisabled( true );
break;
case eParamLensTypeFisheye:
_coef2 ->setIsSecretAndDisabled( true );
_coef3 ->setIsSecretAndDisabled( true );
_coef4 ->setIsSecretAndDisabled( true );
_squeeze -> setIsSecretAndDisabled( true );
_asymmetric -> setIsSecretAndDisabled( true );
break;
case eParamLensTypeFisheye4:
_coef2 ->setIsSecretAndDisabled( false );
_coef3 ->setIsSecretAndDisabled( false );
_coef4 ->setIsSecretAndDisabled( false );
_squeeze -> setIsSecretAndDisabled( true );
_asymmetric -> setIsSecretAndDisabled( true );
break;
Expand Down Expand Up @@ -352,8 +364,9 @@ LensDistortProcessParams<LensDistortPlugin::Scalar> LensDistortPlugin::getProces
params.distort = _reverse->getValue();

params.coef1 = _coef1->getValue();
params.coef2 = _coef2->getValue();
params.coef3 = _coef3->getValue();
params.coef2 = _coef2->getValue();
params.coef3 = _coef3->getValue();
params.coef4 = _coef4->getValue();
params.squeeze = _squeeze->getValue();
params.asymmetric = ofxToGil( _asymmetric->getValue() );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ class LensDistortPlugin : public SamplerPlugin
OFX::ChoiceParam* _normalization;
OFX::DoubleParam* _focal;
OFX::DoubleParam* _coef1; ///< distortion coeffiscient
OFX::DoubleParam* _coef2; ///< distortion coeffiscient for fish-eye lens
OFX::DoubleParam* _coef3; ///< distortion coeffiscient for fish-eye lens
OFX::DoubleParam* _coef2; ///< distortion coeffiscient
OFX::DoubleParam* _coef3; ///< distortion coeffiscient
OFX::DoubleParam* _coef4; ///< distortion coeffiscient
OFX::DoubleParam* _squeeze; ///< squeeze coefficient horizontally/vertically (not implemented yet)
OFX::Double2DParam* _asymmetric; ///< lens distortion is asymmetric horizontally/vertically (not implemented yet)
OFX::Double2DParam* _center; ///< center coordonnates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ void LensDistortPluginFactory::describeInContext( OFX::ImageEffectDescriptor& de
lensType->appendOption( kParamLensTypeBrown1 );
lensType->appendOption( kParamLensTypeBrown3 );
lensType->appendOption( kParamLensTypePTLens );
lensType->appendOption( kParamLensTypeFishEye );
lensType->appendOption( kParamLensTypeFishEye1 );
lensType->appendOption( kParamLensTypeFishEye4 );
lensType->setDefault( eParamLensTypeBrown3 );

OFX::DoubleParamDescriptor* coef1 = desc.defineDoubleParam( kParamCoef1 );
Expand All @@ -136,6 +137,12 @@ void LensDistortPluginFactory::describeInContext( OFX::ImageEffectDescriptor& de
coef3->setDisplayRange( -1.0, 1.0 );
coef3->setHint( "Third distortion coefficient" );

OFX::DoubleParamDescriptor* coef4 = desc.defineDoubleParam( kParamCoef4 );
coef4->setLabel( "Fourth" );
coef4->setDefault( 0.0 );
coef4->setDisplayRange( -1.0, 1.0 );
coef4->setHint( "Fourth distortion coefficient" );

OFX::DoubleParamDescriptor* squeeze = desc.defineDoubleParam( kParamSqueeze );
squeeze->setLabel( "Squeeze" );
#if(!TUTTLE_EXPERIMENTAL)
Expand Down Expand Up @@ -171,7 +178,7 @@ void LensDistortPluginFactory::describeInContext( OFX::ImageEffectDescriptor& de
centerUnit->appendOption( kParamCenterUnitPixel );
centerUnit->appendOption( kParamCenterUnitCenteredNormWidth );
centerUnit->appendOption( kParamCenterUnitNormWidth );
centerUnit->setDefault( eParamCenterUnitPixel );
centerUnit->setDefault( eParamCenterUnitCenteredPixel );

OFX::BooleanParamDescriptor* centerOverlay = desc.defineBooleanParam( kParamCenterOverlay );
centerOverlay->setLabel( "Display distortion center" );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,14 @@ void LensDistortProcess<View>::lensDistort( View& srcView, View& dstView, const
resample_pixels_progress( srcView, dstView, LensUndistortFisheye<double>(_p), procWin, outOfImageProcess, this->getOfxProgress(), sampler );
return;
}
case eParamLensTypeFisheye4:
{
if( _p.distort )
resample_pixels_progress( srcView, dstView, LensDistortFisheye4<double>(_p), procWin, outOfImageProcess, this->getOfxProgress(), sampler );
else
resample_pixels_progress( srcView, dstView, LensUndistortFisheye4<double>(_p), procWin, outOfImageProcess, this->getOfxProgress(), sampler );
return;
}
}
BOOST_THROW_EXCEPTION( exception::Bug()
<< exception::user( "Unrecognized lens type." ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ inline point2<F> transform( const ::tuttle::plugin::lens::LensUndistortFisheye<F
return algo.apply(src);
}

template <typename F, typename F2>
inline point2<F> transform( const ::tuttle::plugin::lens::LensDistortFisheye4<F>& algo, const point2<F2>& src )
{
return algo.apply(src);
}

template <typename F, typename F2>
inline point2<F> transform( const ::tuttle::plugin::lens::LensUndistortFisheye4<F>& algo, const point2<F2>& src )
{
return algo.apply(src);
}

}

namespace tuttle {
Expand Down Expand Up @@ -171,6 +183,13 @@ inline Obj transformValues( const EParamLensType lensType, const LensDistortProc
else
return transformValues( LensUndistortFisheye<double>(params), obj );
}
case eParamLensTypeFisheye4:
{
if( params.distort )
return transformValues( LensDistortFisheye4<double>(params), obj );
else
return transformValues( LensUndistortFisheye4<double>(params), obj );
}
}
BOOST_THROW_EXCEPTION( exception::Unsupported()
<< exception::user( "Unknown lens type." ) );
Expand Down Expand Up @@ -239,6 +258,14 @@ inline void transformValuesApply( const EParamLensType lensType, const LensDisto
transformValuesApply( LensUndistortFisheye<double>(params), obj );
break;
}
case eParamLensTypeFisheye4:
{
if( params.distort )
transformValuesApply( LensDistortFisheye4<double>(params), obj );
else
transformValuesApply( LensUndistortFisheye4<double>(params), obj );
break;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ static const std::string kParamLensType ( "lensType" );
static const std::string kParamLensTypeBrown1 ( "brown1" );
static const std::string kParamLensTypeBrown3 ( "brown3" );
static const std::string kParamLensTypePTLens ( "ptlens" );
static const std::string kParamLensTypeFishEye ( "fish-eye" );
static const std::string kParamLensTypeFishEye1 ( "fisheye1" );
static const std::string kParamLensTypeFishEye4 ( "fisheye4" );
static const std::string kParamCoef1 ( "coef1" );
static const std::string kParamCoef2 ( "coef2" );
static const std::string kParamCoef3 ( "coef3" );
static const std::string kParamCoef4 ( "coef4" );
static const std::string kParamSqueeze ( "squeeze" );
static const std::string kParamAsymmetric ( "asymmetric" );
static const std::string kParamCenter ( "center" );
Expand Down Expand Up @@ -100,6 +102,7 @@ enum EParamLensType
eParamLensTypeBrown3,
eParamLensTypePTLens,
eParamLensTypeFisheye,
eParamLensTypeFisheye4,
};

enum EParamCenterType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ struct LensDistortProcessParams
F coef1;
F coef2;
F coef3;
F coef4;
/// @}

/// @group Advanced
Expand Down Expand Up @@ -488,6 +489,104 @@ struct LensUndistortFisheye : public CoordonatesSystem<F>
};


template<typename F>
struct LensDistortFisheye4 : public CoordonatesSystem<F>
{
LensDistortFisheye4(const LensDistortProcessParams<F>& params)
: CoordonatesSystem<F>(params)
{}
template<typename F2>
inline point2<F> apply( const point2<F2>& src ) const
{
BOOST_ASSERT( this->_params.distort );
point2<F> pc( this->pixelToLensCenterNormalized( src ) ); // centered normalized space
pc.x *= this->_params.postScale.x;
pc.y *= this->_params.postScale.y;

const F r = std::sqrt(pc.x * pc.x + pc.y * pc.y); // distance to center squared
// distortion coef for current pixel
const F coef = distoCoef( this->_params, r );
pc.x *= coef;
pc.y *= coef;

pc.x *= this->_params.preScale.x;
pc.y *= this->_params.preScale.y;
return this->lensCenterNormalizedToPixel( pc ); // original space
}

static F distoCoef(const LensDistortProcessParams<F>& params, F r)
{
const double eps = 1e-8;
const double k1 = params.coef1, k2 = params.coef2, k3 = params.coef3, k4 = params.coef4;
const double theta = std::atan(r);
const double
theta2 = theta*theta,
theta3 = theta2*theta,
theta4 = theta2*theta2,
theta5 = theta4*theta,
theta6 = theta3*theta3,
theta7 = theta6*theta,
theta8 = theta4*theta4,
theta9 = theta8*theta;
const double theta_dist = theta + k1*theta3 + k2*theta5 + k3*theta7 + k4*theta9;
const double inv_r = r > eps ? 1.0/r : 1.0;
const double cdist = r > eps ? theta_dist * inv_r : 1.0;
return cdist;
}
};

template<typename F>
struct LensUndistortFisheye4 : public CoordonatesSystem<F>
{
LensUndistortFisheye4(const LensDistortProcessParams<F>& params)
: CoordonatesSystem<F>(params)
{}
template<typename F2>
inline point2<F> apply( const point2<F2>& src ) const
{
BOOST_ASSERT( !this->_params.distort );
point2<F> pc( this->pixelToLensCenterNormalized( src ) );
pc.x *= this->_params.postScale.x;
pc.y *= this->_params.postScale.y;

const F r = std::sqrt(pc.x * pc.x + pc.y * pc.y); // distance to center squared
// distortion coef for current pixel
const F coef = distoCoef( this->_params, r );
pc.x *= coef;
pc.y *= coef;

pc.x *= this->_params.preScale.x;
pc.y *= this->_params.preScale.y;
return this->lensCenterNormalizedToPixel( pc ); // to the original space
}

static F distoCoef(const LensDistortProcessParams<F>& params, F theta_dist)
{
const double eps = 1e-8;
double scale = 1.0;
if (theta_dist > eps)
{
double theta = theta_dist;
for (int j = 0; j < 10; ++j)
{
const double
theta2 = theta*theta,
theta4 = theta2*theta2,
theta6 = theta4*theta2,
theta8 = theta6*theta2;
theta = theta_dist /
(1.0 + params.coef1 * theta2
+ params.coef2 * theta4
+ params.coef3 * theta6
+ params.coef4 * theta8);
}
scale = std::tan(theta) / theta_dist;
}
return scale;
}
};


}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#define OFXPLUGIN_VERSION_MAJOR 3
#define OFXPLUGIN_VERSION_MAJOR 4
#define OFXPLUGIN_VERSION_MINOR 0

#include <tuttle/plugin/Plugin.hpp>
Expand Down