Lens distortion correction division model 1p
 All Classes Files Functions Variables
image_primitives.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2010-2013, AMI RESEARCH GROUP <lalvarez@dis.ulpgc.es>
3  License : CC Creative Commons "Attribution-NonCommercial-ShareAlike"
4  see http://creativecommons.org/licenses/by-nc-sa/3.0/es/deed.en
5  */
6 
7 
8 #ifndef AMI_DLL_H
9  #define AMI_DLL_H
10 #endif
11 
18 #ifndef IMAGE_PRIMITIVES_H
19 #define IMAGE_PRIMITIVES_H
20 
21 #include "../ami_lens_distortion/lens_distortion_model.h"
22 #include "point2d.h"
23 #include "line_points.h"
24 
25 using namespace std;
26 
27 namespace ami {
35 class AMI_DLL_H image_primitives
36 {
37  std::vector< point2d<double> > points ;
39  std::vector<line_points> lines ;
40  lens_distortion_model distortion ;
41 public :
42 
43  image_primitives(){};
44  image_primitives(double *a,double *b, double *c,int size);
45 
46  std::vector< point2d<double> > projected_3dpoints ;
48 
49  image_primitives & operator=(const image_primitives &primitiva);
50 
51  ~image_primitives(){};
52 
53  void initialize(unsigned int npoints=0, unsigned int nlines=0,
54  unsigned int nellipses=0);
55 
56  bool IsProjected_3dpointsInvalid ();
57 
58 
65  return distortion.get_distortion_center();}
66 
67 
73  std::vector<point2d<double> > &get_points(){return points;}
74 
75  const std::vector<point2d<double> > &get_points() const {return points;}
76 
82  std::vector<line_points> &get_lines(){return lines;}
83 
88  const std::vector<line_points> &get_lines() const {return lines;}
89 
95  const lens_distortion_model &get_distortion() const {return distortion;}
96  lens_distortion_model &get_distortion(){return distortion;}
97 
103  void set_points(const std::vector<point2d<double> > &p2){
104  if(points.size()>0) points.clear(); points=p2;}
105 
111  void set_lines(const std::vector<line_points> &lines2 )
112  {if(lines.size()>0) lines.clear();lines=lines2;}
113 
119  void set_distortion(const lens_distortion_model &distortion2) {distortion=distortion2;}
121 
122  int read (char *name);
123 
124  int write(char *name)
125 {
126  FILE *f;
127  double v1,v2,v3;
128 
129  //OPEN FILE
130  f = fopen(name, "w+");
131  if (!f)
132  return -1;
133 
134  //SAVE DISTORTION MODEL
135  fprintf(f,"DISTORTION MODEL\n");
136  fprintf(f,"distortion center = (%.20g %.20g)\n",distortion.get_distortion_center().x,distortion.get_distortion_center().y);
137  fprintf(f,"Number of distortion parameters = %d\n",(int)distortion.get_d().size());
138  for(unsigned int i=0;i<distortion.get_d().size();i++)
139  {
140  fprintf(f, "value of distortion parameter %d = %.20g\n",i,distortion.get_d()[i]);
141  }
142  //SAVE POINTS
143  /*fprintf(f,"%d POINTS\n",(int)points.size());
144  for(unsigned int i=0;i<points.size();i++)
145  {
146  fprintf(f, "%.20g %.20g\n",points[i].x,points[i].y);
147  }*/
148 
149  //SAVE STRAIGHT
150  fprintf(f,"\nNUMBER OF LINES = %d \n",(int)lines.size());
151  for(unsigned int i=0;i<lines.size();i++)
152  {
153  fprintf(f,"\nline %d \n",(int) i);
154  v1 = lines[i].get_a();
155  v2 = lines[i].get_b();
156  v3 = lines[i].get_c();
157  fprintf(f,"line parameters = %.20g %.20g %.20g\n",v1,v2,v3);
158  fprintf(f,"line points : \n");
159  std::vector<point2d<double> > puntos = lines[i].get_points();
160  fprintf(f,"%d\n",(int)puntos.size());
161  for(unsigned int j=0;j<puntos.size();j++)
162  {
163  fprintf(f, "%.20g %.20g\n",puntos[j].x,puntos[j].y);
164  }
165  }
166 
167 
168 
169  /* WE STORE 3D POINTS PROJECTED COORDINATES*/
170  //fprintf(f,"\n%d 3D_POINTS_PROJECTED_COORDINATES \n",(int)projected_3dpoints.size());
171  /*for(unsigned int i=0;i<projected_3dpoints.size();i++)
172  {
173  fprintf(f, "%.15f %.15f\n",projected_3dpoints[i].x,projected_3dpoints[i].y);
174  }*/
175 
176  //CLOSE FILE
177  fclose(f);
178 
179  return 0;
180 }
181 
182  unsigned int Num_Puntos() const;
183 
184 friend inline std::ostream &operator <<(std::ostream &s,
185  const image_primitives &ip) {
186  s << "Points " << ip.points.size() << std::endl;
187  for(unsigned int i=0;i<ip.points.size();i++)
188  {
189  s << "(" << ip.points[i].x << ", " << ip.points[i].y << ") ";
190  }
191  s << std::endl;
192  s << "Lines " << ip.lines.size() << std::endl;
193  for(unsigned int i=0; i<ip.lines.size();i++)
194  {
195  s << "(" << ip.lines[i].get_a() << ", " << ip.lines[i].get_b() <<
196  ", " << ip.lines[i].get_c() << ", " << std::endl;
197  }
198  s << std::endl;
199  s << "Distortion model " << std::endl;
200  s << "( " << ip.distortion.get_distortion_center().x << ", " <<
201  ip.distortion.get_distortion_center().y << ") ";
202  for(unsigned int i=0;i<ip.distortion.get_d().size();i++)
203  {
204  s << ip.distortion.get_d()[i] << " ";
205  }
206  s << std::endl;
207  return s;
208 }
209 
210 bool is_empty();
211 void clear();
212 void find_nearest_point_in_primitives(point2d<double> &pto,
213  point2d<double> &pto_out,double &distance,
214  int &type_prim,int &prim,int &pos);
215 
216 void find_nearest_point_in_others_primitives(point2d<double> &pto,
217  point2d<double> &pto_out,
218  double &distance, int &type_prim,
219  int &prim,int &pos);
220 void find_nearest_line_equation(point2d<double> &pto,double &distance,
221  int &prim);
222 };
223 
224 }
225 
226 #endif
line_points class AMI_DLL_H to store line equation and associated points
void set_points(const std::vector< point2d< double > > &p2)
Set points collection.
Definition: image_primitives.h:103
void set_lines(const std::vector< line_points > &lines2)
Set Lines collection.
Definition: image_primitives.h:111
point2d< double > & get_distortion_center()
This function returns the center of the lens distortion model.
Definition: lens_distortion_model.h:82
Class to store distortion model and basic methods.
Definition: lens_distortion_model.h:38
T x
Definition: point2d.h:37
void set_distortion(const lens_distortion_model &distortion2)
Set distortion model.
Definition: image_primitives.h:119
class to store the image primitives (points, lines, ellipses and ditortion model) ...
Definition: image_primitives.h:35
const point2d< double > get_distorsion_center() const
Return distortion center.
Definition: image_primitives.h:64
T y
Definition: point2d.h:38
std::vector< line_points > & get_lines()
Return line_points collection.
Definition: image_primitives.h:82
std::vector< point2d< double > > & get_points()
Return points.
Definition: image_primitives.h:73
std::vector< double > & get_d()
This function returns the vector with the lens distortion model parameters.
Definition: lens_distortion_model.h:52
int write(char *name)
Definition: image_primitives.h:124
lens_distortion_model & get_distortion()
Return distortion model.
Definition: image_primitives.h:96
point2d class definition