TuttleOFX
1
|
00001 #ifndef _LENSDISTORTPROCESSPARAMS_HPP_ 00002 #define _LENSDISTORTPROCESSPARAMS_HPP_ 00003 00004 #include <tuttle/plugin/global.hpp> 00005 #include <terry/globals.hpp> 00006 00007 namespace tuttle { 00008 namespace plugin { 00009 namespace lens { 00010 00011 /** 00012 * @brief Contains functions to map coordinates between : 00013 * * canonical coordinates system (ofx) 00014 * e.g PAL D1 00015 * ----------------------------- 720.0, 576.0 00016 * | | 00017 * | | 00018 * | | 00019 * | | 00020 * | | 00021 * ----------------------------- 00022 * 0.0, 0.0 00023 * * centered normalized coordinate system (custom, only depending on image width) 00024 * ----------------------------- 0.5, 0.5 00025 * | | 00026 * |---------------------------| 00027 * | | 00028 * | | 00029 * | 0.0, 0.0 | 00030 * | | 00031 * | | 00032 * |---------------------------| 00033 * | | 00034 * ----------------------------- 00035 * -0.5, -0.5 00036 */ 00037 template<typename F> 00038 class CoordonatesSystemParams 00039 { 00040 public: 00041 typedef F Float; 00042 typedef boost::gil::point2<Float> Point2; 00043 00044 public: 00045 Point2 _imgSizeSrc; 00046 Point2 _imgCenterSrc; 00047 Point2 _imgCenterDst; 00048 F _imgHalfDiagonal; ///< half diagonal of the image (to work between -0.5 and 0.5) 00049 F _pixelRatio; 00050 00051 public: 00052 virtual ~CoordonatesSystemParams() = 0; 00053 00054 /// @{ conversion functions 00055 inline Point2 pixelToNormalized( const Point2& p ) const 00056 { 00057 BOOST_STATIC_ASSERT( boost::is_floating_point<F>::value ); 00058 BOOST_STATIC_ASSERT( ( boost::is_same<F, double>::value ) ); 00059 Point2 pn( p / _imgHalfDiagonal ); 00060 pn.x *= _pixelRatio; 00061 return pn; 00062 } 00063 00064 inline Point2 normalizedToPixel( const Point2& pn ) const 00065 { 00066 Point2 p( pn * _imgHalfDiagonal ); 00067 00068 p.x /= _pixelRatio; 00069 return p; 00070 } 00071 00072 inline Point2 pixelToCenterNormalized( const Point2& p ) const 00073 { 00074 return pixelToNormalized( p - _imgCenterSrc ); 00075 } 00076 00077 template<typename F2> 00078 inline Point2 pixelToCenterNormalized( const boost::gil::point2<F2>& p ) const 00079 { 00080 Point2 pp( p.x, p.y ); 00081 00082 return pixelToCenterNormalized( pp ); 00083 } 00084 00085 inline Point2 centerNormalizedToPixel( const Point2& pn ) const 00086 { 00087 return normalizedToPixel( pn ) + _imgCenterDst; 00088 } 00089 00090 /// @} 00091 }; 00092 00093 template<typename F> 00094 CoordonatesSystemParams<F>::~CoordonatesSystemParams() {} 00095 00096 template<typename F> 00097 class NormalLensDistortParams : public CoordonatesSystemParams<F> 00098 { 00099 public: 00100 typedef typename CoordonatesSystemParams<F>::Point2 Point2; 00101 00102 public: 00103 bool _distort; ///< true : distort, false : undistort 00104 F _coef1; 00105 00106 Point2 _lensCenterDst; ///< center of the lens ditortion in the dest image coordinates (in pixels) 00107 Point2 _lensCenterSrc; ///< center of the lens ditortion in the source image coordinates (in pixels) 00108 Point2 _postScale; 00109 Point2 _preScale; 00110 00111 public: 00112 virtual ~NormalLensDistortParams() {} 00113 00114 inline Point2 pixelToLensCenterNormalized( const Point2& p ) const 00115 { 00116 return this->pixelToNormalized( p - this->_lensCenterDst ); 00117 } 00118 00119 template<typename F2> 00120 inline Point2 pixelToLensCenterNormalized( const boost::gil::point2<F2>& p ) const 00121 { 00122 Point2 pp( p.x, p.y ); 00123 00124 return pixelToLensCenterNormalized( pp ); 00125 } 00126 00127 inline Point2 lensCenterNormalizedToPixel( const Point2& pn ) const 00128 { 00129 return this->normalizedToPixel( pn ) + this->_lensCenterSrc; 00130 } 00131 00132 }; 00133 00134 template<typename F> 00135 class NormalLensUndistortParams : public NormalLensDistortParams<F> 00136 { 00137 public: 00138 virtual ~NormalLensUndistortParams() {} 00139 00140 }; 00141 00142 template<typename F> 00143 class FisheyeLensDistortParams : public NormalLensUndistortParams<F> 00144 { 00145 public: 00146 F _coef2; 00147 00148 public: 00149 virtual ~FisheyeLensDistortParams() {} 00150 }; 00151 00152 template<typename F> 00153 class FisheyeLensUndistortParams : public FisheyeLensDistortParams<F> 00154 { 00155 public: 00156 virtual ~FisheyeLensUndistortParams() {} 00157 }; 00158 00159 template<typename F> 00160 class AdvancedLensDistortParams : public FisheyeLensUndistortParams<F> 00161 { 00162 public: 00163 typedef typename CoordonatesSystemParams<F>::Point2 Point2; 00164 00165 public: 00166 F _squeeze; 00167 Point2 _asymmetric; 00168 00169 public: 00170 virtual ~AdvancedLensDistortParams() {} 00171 }; 00172 00173 template<typename F> 00174 class AdvancedLensUndistortParams : public AdvancedLensDistortParams<F> 00175 { 00176 public: 00177 virtual ~AdvancedLensUndistortParams() {} 00178 }; 00179 00180 template<typename F> 00181 class LensDistortProcessParams : public AdvancedLensUndistortParams<F> 00182 { 00183 public: 00184 virtual ~LensDistortProcessParams() {} 00185 }; 00186 00187 } 00188 } 00189 } 00190 00191 #endif