ldpk
tde4_ldp_radial_deg_6_decentered_deg_2_opencv.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <ldpk/ldpk_ldp_builtin.h>
5 
9 
12 template <class VEC2,class MAT2>
14  {
15 private:
16  typedef VEC2 vec2_type;
17  typedef MAT2 mat2_type;
19 
21 
22  static const char* _para[5];
23 protected:
24  bool decypher(const char* name,int& i)
25  {
26  typedef base_type bt;
27  int n;
29  for(i = 0;i < n;++i)
30  {
31  if(0 == strcmp(name,_para[i]))
32  {
33  return true;
34  }
35  }
36  return false;
37  }
53  {
54  typedef base_type bt;
55  bt::check_builtin_parameters();
56  _radial.set_rho(bt::r_fb_cm() / bt::fl_cm());
57  return true;
58  }
59  bool getNumParameters(int& n)
60  {
61  n = 5;
62  return true;
63  }
64  bool getParameterName(int i,char* identifier)
65  {
66  strcpy(identifier,_para[i]);
67  return true;
68  }
70  bool setParameterValue(const char *identifier,double v)
71  {
72  typedef base_type bt;
73  int i;
74 // Does the base class know the parameter?
75  if(bt::set_builtin_parameter_value(identifier,v))
76  {
77  return true;
78  }
79  if(!decypher(identifier,i))
80  {
81  return false;
82  }
83  if(i < 5)
84  {
85  if(_radial.get_coeff(i) != v)
86  { bt::no_longer_uptodate_lut(); }
87  _radial.set_coeff(i,v);
88  }
89  return true;
90  }
91 // virtual bool undistort(double x0,double y0,double &x1,double &y1)
92  virtual bool distort(double x0,double y0,double &x1,double &y1)
93  {
94  typedef base_type bt;
95  vec2_type q = bt::map_dn_to_unit(
96  _radial.eval(
97  bt::map_unit_to_dn(vec2_type(x0,y0))));
98  x1 = q[0];
99  y1 = q[1];
100  return true;
101  }
102 // virtual bool distort(double x0,double y0,double &x1,double &y1)
103  virtual bool undistort(double x0,double y0,double &x1,double &y1)
104  {
105  typedef base_type bt;
106 // The distort-method without initial values is not constant by semantics,
107 // since it may cause an update of the lookup-tables. Implementing a Nuke node
108 // it turned out that we need to prevent threads from trying so simultaneously.
109 // By the following double check of is_uptodate_lut() we keep the mutex lock
110 // out of our frequently called distort stuff (for performance reasons) and
111 // prevent threads from updating without need.
112  if(!bt::is_uptodate_lut())
113  {
114  bt::lock();
115  if(!bt::is_uptodate_lut())
116  {
117  bt::update_lut();
118  }
119  bt::unlock();
120  }
121 
122 // Get initial value from lookup-table
123  vec2_type qs = bt::get_lut().get_initial_value(vec2_type(x0,y0));
124 // Call version of distort with initial value.
125  vec2_type q = bt::map_dn_to_unit(
126  _radial.map_inverse(
127  bt::map_unit_to_dn(vec2_type(x0,y0)),
128  bt::map_unit_to_dn(qs)));
129  x1 = q[0];
130  y1 = q[1];
131  return true;
132  }
133 /*
134  virtual bool distort(double x0,double y0,double x1_start,double y1_start,double &x1,double &y1)
135  {
136  typedef base_type bt;
137  vec2_type q = bt::map_dn_to_unit(
138  _radial.map_inverse(
139  bt::map_unit_to_dn(vec2_type(x0,y0)),
140  bt::map_unit_to_dn(vec2_type(x1_start,y1_start))));
141  x1 = q[0];
142  y1 = q[1];
143  return true;
144  }
145 */
146 public:
147 // Mutex initialized and destroyed in baseclass.
149  { }
151  { }
152  bool getModelName(char *name)
153  {
154 #ifdef LDPK_COMPILE_AS_PLUGIN_SDV
155  strcpy(name,"OpenCV Radial Degree 6, Decentered Degree 2 [Plugin]");
156 #else
157  strcpy(name,"OpenCV Radial Degree 6, Decentered Degree 2");
158 #endif
159  return true;
160  }
161  bool getParameterType(const char* identifier,tde4_ldp_ptype& ptype)
162  {
163  typedef base_type bt;
164  int i;
165  if(bt::get_builtin_parameter_type(identifier,ptype)) return true;
166  if(!decypher(identifier,i)) return false;
167  ptype = TDE4_LDP_ADJUSTABLE_DOUBLE;
168  return true;
169  }
170  bool getParameterDefaultValue(const char* identifier,double& v)
171  {
172  typedef base_type bt;
173  int i;
174  if(!decypher(identifier,i)) return false;
175  v = 0.0;
176  return true;
177  }
178  bool getParameterRange(const char* identifier,double& a,double& b)
179  {
180  typedef base_type bt;
181  int i;
182  if(!decypher(identifier,i)) return false;
183  if((i == 0) || (i == 1) || (i == 4))
184  {
185 // Distortion - Degree 2, Distortion - Degree 4, Distortion - Degree 6
186  a = -0.5;b = 0.5;
187  }
188  else if((i == 2) || (i == 3))
189  {
190 // Decentering X/Y
191  a = -0.5;b = 0.5;
192  }
193  return true;
194  }
195  bool getJacobianMatrix(double x0,double y0,double& m00,double& m01,double& m10,double& m11)
196  {
197  typedef base_type bt;
198  mat2_type m = _radial.jacobi(
199  bt::map_unit_to_dn(vec2_type(x0,y0)));
200 // to myself: Eigentlich w/2,h/2 bei beiden. Kuerzt sich weg.
201  mat2_type u2d(bt::w_fb_cm() / bt::r_fb_cm(),0.0,0.0,bt::h_fb_cm() / bt::r_fb_cm());
202  mat2_type d2u(bt::r_fb_cm() / bt::w_fb_cm(),0.0,0.0,bt::r_fb_cm() / bt::h_fb_cm());
203  m = d2u * m * u2d;
204  m00 = m[0][0];m01 = m[0][1];m10 = m[1][0];m11 = m[1][1];
205  return true;
206  }
207  };
208 
209 template <class VEC2,class MAT2>
211  "Radial Distortion - Degree 2 - k1",
212  "Radial Distortion - Degree 4 - k2",
213  "Decentering Y - Degree 2 - p1",
214  "Decentering X - Degree 2 - p2",
215  "Radial Distortion - Degree 6 - k3",
216  };
217 
mat2_type jacobi(const vec2_type &p_dn) const
Analytic version of the Jacobi-matrix. By definition, we are working in dn-coordinates here...
Definition: ldpk_radial_decentered_distortion_opencv.h:135
bool getParameterName(int i, char *identifier)
returns "identifier" name of parameter "i" (maximum length of "identifier": 100 bytes)...
Definition: tde4_ldp_radial_deg_6_decentered_deg_2_opencv.h:64
double get_coeff(int i) const
Get coefficient c[i], 0 <= i < 5.
Definition: ldpk_radial_decentered_distortion_opencv.h:99
virtual bool undistort(double x0, double y0, double &x1, double &y1)
warp/unwarp 2D points...
Definition: tde4_ldp_radial_deg_6_decentered_deg_2_opencv.h:103
bool getParameterType(const char *identifier, tde4_ldp_ptype &ptype)
returns type of given parameter... The method should return false, if the parameter addressed by iden...
Definition: tde4_ldp_radial_deg_6_decentered_deg_2_opencv.h:161
bool initializeParameters()
Implies setting the rho-factor for mapping between dn- and OpenCV-coordinates. rho is based on the fo...
Definition: tde4_ldp_radial_deg_6_decentered_deg_2_opencv.h:52
bool getParameterRange(const char *identifier, double &a, double &b)
returns range for adjustable double parameters...
Definition: tde4_ldp_radial_deg_6_decentered_deg_2_opencv.h:178
vec2_type eval(const vec2_type &p) const
Same as method instead of operator.
Definition: ldpk_generic_distortion_base.h:77
bool getParameterDefaultValue(const char *identifier, double &v)
returns default value for given parameter (maximum length of "char *v": 1000 bytes)......
Definition: tde4_ldp_radial_deg_6_decentered_deg_2_opencv.h:170
bool getModelName(char *name)
returns a name for the model as to show up in the GUI (maximum length of "name": 100 bytes)...
Definition: tde4_ldp_radial_deg_6_decentered_deg_2_opencv.h:152
This class handles the built-in parameter and the lookup table. You may find it useful for your own d...
Definition: ldpk_ldp_builtin.h:31
virtual vec2_type map_inverse(const vec2_type &q) const
Inverse mapping by solving the fixed point equation without providing initial values. Virtual, because the derived class might use some smart data structure for calculating an initial value.
Definition: ldpk_generic_distortion_base.h:95
void set_coeff(int i, double q)
Set coefficient c[i], 0 <= i < 6.
Definition: ldpk_radial_decentered_distortion_opencv.h:105
bool setParameterValue(const char *identifier, double v)
Model parameters in OpenCV coordinates.
Definition: tde4_ldp_radial_deg_6_decentered_deg_2_opencv.h:70
Plugin class for radial distortion with decentering Not sure if parameters can be calculated by 3DE&#39;s...
Definition: tde4_ldp_radial_deg_6_decentered_deg_2_opencv.h:13
bool getNumParameters(int &n)
returns the number of plugin parameters...
Definition: tde4_ldp_radial_deg_6_decentered_deg_2_opencv.h:59
bool getJacobianMatrix(double x0, double y0, double &m00, double &m01, double &m10, double &m11)
calculate the Jacobian matrix of the undistort()-Method. Overwrite this, if you know the Jacobian for...
Definition: tde4_ldp_radial_deg_6_decentered_deg_2_opencv.h:195
A polynomial radially symmetric model of degree 6 with decentering degree 2 as defined in OpenCV...