KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
omap_computer.h
Go to the documentation of this file.
1 /*
2 omap_computer.h
3 
4 @author - Josh Bowdish - original Matlab code by David C. Lee
5 
6 omap_computer is the base for all the functions under compute_omap.m
7 
8 function tree for compute_omap:
9 
10 compute_orientationmap
11  orient_from_lines
12  sample_line
13  extend_line
14  move_line_towards_vp
15  sample_line
16 */
17 
18 #ifndef omap_computer
19 #define omap_computer
20 
21 //includes!
22 #include <edge_cpp/line_segment.h>
23 #include "i_cpp/i_image.h"
24 #include "m_cpp/m_vector.h"
25 #include "m_cpp/m_matrix.h"
26 #include "g_cpp/g_util.h"
27 #include "g/g_geometry.h"
29 
30 namespace kjb
31 {
32 
33 class Omap_segment{
34 
35  private:
36 
37  //variables
38  double n_sample;//the "length" of the line
39  std::vector<kjb::Vector> sample;//A vector of spacings on the line (linspace)
40  int lineclass;//which vanishing point the line is associated with (0-2)
41  Vanishing_point vp;
42 
43  Vector startpoint;
44  Vector endpoint;
45 
46  public:
47  //constructors
48  Omap_segment();
50  Omap_segment(Vector startpoint,Vector endpoint);
51  Omap_segment(Vector startpoint,Vector endpoint,int lineclass);
52  Omap_segment(double x1,double y1, double x2,double y2);
53  Omap_segment(double x1,double y1, double x2,double y2,int lineclass);
54 
55  //methods that do
56  void develop_sample();
57 
58  //setters
59  void set_lineclass(int lc);
60  void set_vp(const Vanishing_point & vanishingp);
61  //getters
62  double get_n_sample(){ return n_sample; }
63  std::vector<kjb::Vector> get_sample(){ return sample; }
64  int get_lineclass(){ return lineclass; }
65  kjb::Vector get_start_point(){ return startpoint; }
66  kjb::Vector get_end_point(){ return endpoint; }
67  double get_start_x();
68  double get_start_y();
69  double get_end_x();
70  double get_end_y();
71  Vanishing_point get_vp(){ return vp; }
72 
73 }; //end class Omap_segment
74 
76 {
77 public:
83  };
84  private:
85 
86  //variables
87  bool using_featman_lines;
88  bool delete_features;
89 
90  std::string imagename;
91  std::string dname;
92  Features_manager * featman;
93  std::vector<Vanishing_point> vpts;
94  double focal_length;
95  const Manhattan_world * mw;
96  double imgsize;
97  int imageheight;
98  int imagewidth;
99  unsigned numlines;
100  std::vector<Omap_segment> lines;
101  std::vector<std::vector<std::vector<Matrix> > > lineextimg;
102 
103  std::vector<Omap_segment> lines_at_1;
104  std::vector<Omap_segment> lines_at_2;
105  std::vector<Omap_segment> lines_at_3;
106 
107  //for extend_line
108  // std::vector<kjb::Vector> get_sample(){ return sample; }
109  std::vector<kjb::Vector> mastersamples;
110  std::vector<int> mastersamplelc;
111  std::vector<kjb::Vector> samples_at_0; //samples of lines associated with vp 0
112  std::vector<kjb::Vector> samples_at_1;
113  std::vector<kjb::Vector> samples_at_2;
114  std::vector<kjb::Vector> samples_at_3;
115 
116  unsigned sample_rate;
117 
118  //methods
119 
120  /*
121  IN PROGRESS
122  Takes the lines and associates them with the vanishing points it thinks are appropriate
123  Sets up the lines variable (of Omap_segments)/
124  */
125  void taglinesvp(){
126 
127  }
128  /*
129  orient_from_lines() - Only called once there is a set of lines to orient_from.
130  This function fills in the lineextimg variable. It goes through each line and
131  tries to see how much area it can describe the orientation of using extend_line().
132  It adds that to a mask, which is layered on top of the appropriate section of
133  lineextimg.
134  */
135  std::vector<std::vector<std::vector<Matrix> > > orient_from_lines(); //[][][] where each [] is a pair
136  //[][][] of imgheight,imgwidth
137  //[][][] matrix of line overlaps
138  //(its [3][3][2])
139 
140  /*
141  sample_line() - This method is only called once. Goes through each of the lines
142  found in the image and develops the "std::vector<Omap_segment> lines" variable
143  For each line attached to an actual VP, it calculates
144  lines(i).n_sample - length
145  lines(i).sample - linspace(startpoint,endpoint)
146  lines(i).lineclass - which vp it's attached to (0-2)
147  */
148  void sample_line();
149 
150  /*
151  extend_line() - Called twice for every line. Takes the line and attempts to
152  extend its area (creating a trapezoid) toward the vanishing point. It stops
153  if the line does one of several things:
154  1) if the extension goes beyond the edge of the image
155  2) if the extension hits the vanishing point
156  3) if the extension intersects (approximately) any of the lines that point
157  toward the other vanishing point (The one that isn't being extended to).
158 
159  */
160  Matrix extend_line
161  (
162  Omap_segment line,
163  Vanishing_point vp,
164  int toward_or_away,
165  std::vector<kjb::Vector> sample,
166  int imgheight,
167  int imgwidth
168  );
169 
170  /* private copy constructor */
171  Omap_computer(const Omap_computer & src)
172  {
173  (*this) = src;
174  }
175 
177  Omap_computer & operator=(const Omap_computer & /* src */)
178  {
179  return (*this);
180  }
181 
182  public:
183 
185  {
186  if(delete_features)
187  {
188  delete featman;
189  }
190  }
191 
192  //constructors
193 
194  /*
195  Takes a filepath to an already computed feature file for the image. It will
196  then compute from the features. It has no reference to the actual image.
197  Note: Preferred/fastest constructor
198 
199  @param - filepath to the pre-computed features
200  */
202  (
203  const char* featurepath,
204  const char* filename
205  );
206 
207  /*
208  Takes the file with lines, the file with the vp and the image file (mostly to
209  make this constructor different from the 2 (const char*) constructor). It will
210  then compute from the lines and vps given to it.
211 
212  Edit: included featurepath because it was giving me an error for invoking
213  features_manager's blank constructor... even though I didn't
214  Note: takes the files I built from matlab, need to be of specific construction
215  */
217  (
218  const char* linepath,
219  const char* vppath,
220  const char* featurepath,
221  const char* filename
222  );
223 
224  /*
225  Calls the const char* one when the input is a little different
226  WARNING: Doesn't work with bestfeatures.txt files yet. (or anything else for that matter)
227  Out of commission until I understand why it doesn't work.
228  */
229  Omap_computer(const std::string featurepath);
230 
231  /*
232  Takes the image object (not the filepath) and constructs a featuremanager from
233  it.
234  Note: takes a while to extract lines and things.
235 
236  @param - Image object to analyse
237  */
238 
239  Omap_computer(const Image & img);
240 
242 
243  //methods that do calculations
244 
245  /*
246  @param - point1 - start point of the line
247  point2 - end point of the line
248  vp - the vanishing point you want to extend toward
249  amount - the distance to attempt
250  */
251  std::vector<double> move_line_towards_vp
252  ( // public for now
253  Vector point1,
254  Vector point2,
255  Vanishing_point vp,
256  double amount
257  );
258 
259  /*
260  Initialises lineextimg...
261  calls orient_from_lines()...
262  once lineextimg is filled out, computes the actual orientation maps by
263  and-ing/or-ing variations of lineextimg's parts.
264  */
265  void compute_omap
266  (
267  Image & out_omap,
268  Orientation_map_type omap_type
269  );
270 
271  //getters
273  std::vector<Omap_segment> get_lines();
274  std::vector<Vanishing_point> get_vpts();
275  double get_imgsize();
277  std::vector<kjb::Vector> get_samples();
278  std::vector<int> get_lineclasses();
279 
280  void set_lines_at_1(std::vector<Omap_segment> lineset);
281  void set_lines_at_2(std::vector<Omap_segment> lineset);
282  void set_lines_at_3(std::vector<Omap_segment> lineset);
283 
284  std::vector<Omap_segment> get_lines_at_vp(int vp);
285  std::vector<Omap_segment> get_lines_at_1();
286  std::vector<Omap_segment> get_lines_at_2();
287  std::vector<Omap_segment> get_lines_at_3();
288 
289  std::vector<kjb::Vector> get_samples_at_vp(int vp);
290  std::vector<kjb::Vector> get_samples_at_0();
291  std::vector<kjb::Vector> get_samples_at_1();
292  std::vector<kjb::Vector> get_samples_at_2();
293  std::vector<kjb::Vector> get_samples_at_3();
294 
295  //constructor asisstants
296  std::vector<Omap_segment> read_matlab_line_file(const char* linepath);
297  std::vector<Vanishing_point> read_matlab_vp_file(const char* vppath);
299 
300  /*
301  prints a file with all the lines that have vanishing points associated with
302  them in the following format, (per line)
303  "startx starty endx endy vp"
304  */
305  void print_lines(std::string filename);
306  void print_lines(const char* filename);
307 
308  //I suppose I should probably move these to m_cpp/m_matrix
309  void print_matrix_as_image(std::string filename,Matrix printme,int red,int green, int blue);
310  void print_matrix_as_image_gray(std::string filename,Matrix printme);
312  (
313  Image & tricolor_image,
314  const Matrix & red,
315  const Matrix & green,
316  const Matrix & blue
317  );
318 
319  double compare_images(std::string source, std::string check);
320  double compare_sample_files(std::string source, std::string check,std::string name);
321 
322 
323 }; //end class Omap_computer
324 
325 }
326 
327 #endif
Declarations for Line class.
Definition: omap_computer.h:33
kjb::Vector get_n_samples()
double get_start_y()
Definition: omap_computer.cpp:1145
Definition for the Matrix class, a thin wrapper on the KJB Matrix struct and its related functionalit...
kjb::Vector get_start_point()
Definition: omap_computer.h:65
y2
Definition: APPgetLargeConnectedEdges.m:125
void set_lineclass(int lc)
Definition: omap_computer.cpp:1112
std::vector< Omap_segment > get_lines_at_vp(int vp)
Definition: omap_computer.cpp:867
Definition: omap_computer.h:75
std::vector< kjb::Vector > get_samples_at_3()
Definition: omap_computer.cpp:886
std::vector< kjb::Vector > get_samples_at_vp(int vp)
Definition: omap_computer.cpp:888
std::vector< int > get_lineclasses()
Definition: features_manager.h:55
A vanishing point for a set of parallel lines in an image.
Definition: vanishing_point.h:37
Edge_segment_set get_edge_segments()
Definition: omap_computer.cpp:862
Definition: omap_computer.h:81
This class implements vectors, in the linear-algebra sense, with real-valued elements.
Definition: m_vector.h:87
double get_end_y()
Definition: omap_computer.cpp:1155
int get_lineclass()
Definition: omap_computer.h:64
void initialize_lines_and_samples()
Definition: omap_computer.cpp:578
Orientation_map_type
Definition: omap_computer.h:78
Vector sample(const MV_gaussian_distribution &dist)
Sample from a multivariate normal distribution.
Definition: prob_sample.cpp:42
Definition: omap_computer.h:79
double get_imgsize()
Definition: omap_computer.cpp:881
x1
Definition: APPgetLargeConnectedEdges.m:122
double compare_images(std::string source, std::string check)
Definition: omap_computer.cpp:992
Omap_segment()
Definition: omap_computer.cpp:1058
std::vector< Omap_segment > read_matlab_line_file(const char *linepath)
Definition: omap_computer.cpp:522
kjb::Vector get_end_point()
Definition: omap_computer.h:66
std::vector< Omap_segment > get_lines_at_1()
Definition: omap_computer.cpp:877
Definition: omap_computer.h:82
void print_matrix_as_image_gray(std::string filename, Matrix printme)
Definition: omap_computer.cpp:721
void set_lines_at_1(std::vector< Omap_segment > lineset)
Vanishing_point get_vp()
Definition: omap_computer.h:71
double get_n_sample()
Definition: omap_computer.h:62
std::vector< Omap_segment > get_lines()
Definition: omap_computer.cpp:861
y1
Definition: APPgetLargeConnectedEdges.m:124
void compute_omap(Image &out_omap, Orientation_map_type omap_type)
Definition: omap_computer.cpp:177
x2
Definition: APPgetLargeConnectedEdges.m:123
void print_matrix_as_image(std::string filename, Matrix printme, int red, int green, int blue)
Definition: omap_computer.cpp:700
This class contains the three orthogonal vanishing points defining a Manhattan scene, where most or all planes are aligned with three main orthogonal directions. This class optionally contains a set of segments from the scene, assigned to the correct vanishing point.
Definition: manhattan_world.h:460
std::vector< kjb::Vector > get_samples_at_0()
Definition: omap_computer.cpp:883
void set_lines_at_3(std::vector< Omap_segment > lineset)
double get_end_x()
Definition: omap_computer.cpp:1150
double get_start_x()
Definition: omap_computer.cpp:1140
std::vector< kjb::Vector > get_samples()
void develop_sample()
Definition: omap_computer.cpp:1120
~Omap_computer()
Definition: omap_computer.h:184
std::vector< double > move_line_towards_vp(Vector point1, Vector point2, Vanishing_point vp, double amount)
Definition: omap_computer.cpp:346
std::vector< kjb::Vector > get_samples_at_2()
Definition: omap_computer.cpp:885
std::vector< Vanishing_point > read_matlab_vp_file(const char *vppath)
Definition: omap_computer.cpp:663
This class implements matrices, in the linear-algebra sense, with real-valued elements.
Definition: m_matrix.h:94
Code for a wrapper class around the C struct KJB_Image.
std::vector< Omap_segment > get_lines_at_2()
Definition: omap_computer.cpp:878
std::vector< Vanishing_point > get_vpts()
Definition: omap_computer.cpp:865
Class to manipulate a set of edge segments.
Definition: line_segment_set.h:128
Wrapped version of the C struct KJB_image.
Definition: i_image.h:76
Definition: omap_computer.h:80
std::vector< kjb::Vector > get_sample()
Definition: omap_computer.h:63
void compute_tricolor_image(Image &tricolor_image, const Matrix &red, const Matrix &green, const Matrix &blue)
Definition: omap_computer.cpp:757
Definition for the Vector class, a thin wrapper on the KJB Vector struct and its related functionalit...
void set_vp(const Vanishing_point &vanishingp)
Definition: omap_computer.cpp:1116
A manhattan segment defined by a line segment and the vanishing point it converges to...
Definition: manhattan_world.h:42
void print_lines(std::string filename)
double compare_sample_files(std::string source, std::string check, std::string name)
Definition: omap_computer.cpp:899
void set_lines_at_2(std::vector< Omap_segment > lineset)
std::vector< kjb::Vector > get_samples_at_1()
Definition: omap_computer.cpp:884
std::vector< Omap_segment > get_lines_at_3()
Definition: omap_computer.cpp:879