KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
features_manager.h
Go to the documentation of this file.
1 /* $Id $ */
2 
15 #ifndef EDGE_FEATURES_MANAGER_H
16 #define EDGE_FEATURES_MANAGER_H
17 
18 #include "l_cpp/l_exception.h"
19 #include "l_cpp/l_readable.h"
20 #include "l_cpp/l_writeable.h"
22 #include "edge_cpp/edge.h"
24 
25 #define FM_DEFAULT_EDGE_SIGMA 1.0
26 #define FM_DEFAULT_EDGE_BEGIN 2.55
27 #define FM_DEFAULT_EDGE_END 2.04
28 #define FM_DEFAULT_EDGE_PADDING 30
29 #define FM_DEFAULT_VP_SUCCESS_PROBABILITY 0.999
30 #define FM_DEFAULT_VP_ASSIGNMENT_THRESHOLD 0.16
31 
32 namespace kjb {
55 class Features_manager : public Readable, public Writeable
56 {
57  public:
58 
62  (
63  const kjb::Image & img,
64  bool idetect_edges = true,
65  bool ifit_edge_segments = true,
66  bool icreate_manhattan_world = true
67  );
68 
72  (
73  bool read_image,
74  const std::string & img_path,
75  bool idetect_edges = true,
76  bool ifit_edge_segments = true,
77  bool icreate_manhattan_world = true
78  );
79 
83  (
84  kjb::Edge_set * edges,
85  Edge_segment_set * edge_segments,
86  Manhattan_world * manhattan_world
87  );
88 
92  (
93  const kjb::Image & img,
94  float iblurring_sigma,
95  float ibegin_threshold,
96  float iend_threshold,
97  unsigned int ipadding,
98  bool iuse_fourier,
99  double ivanishing_point_detection_success_probability = FM_DEFAULT_VP_SUCCESS_PROBABILITY,
100  double ioutlier_threshold_for_vanishing_points_assignment = FM_DEFAULT_VP_ASSIGNMENT_THRESHOLD,
101  bool idetect_edges = true,
102  bool ifit_edge_segments = true,
103  bool icreate_manhattan_world = true
104  );
105 
107  Features_manager(std::istream & in) : Readable(), Writeable(),
108  edges(0), edge_segments(0), manhattan_world(0),
109  _edges_available(false),_edge_segments_available(false),
110  _manhattan_world_available(false)
111  {
112  read(in);
113  }
114 
116  Features_manager(const char * filename) : Readable(), Writeable(),
117  edges(0), edge_segments(0), manhattan_world(0),
118  _edges_available(false),_edge_segments_available(false),
119  _manhattan_world_available(false)
120  {
121  Readable::read(filename);
122  }
123 
125  {
126  delete manhattan_world;
127  delete edge_segments;
128  delete edges;
129  }
130 
133  (
134  float iblurring_sigma,
135  float ibegin_threshold,
136  float iend_threshold,
137  unsigned int ipadding,
138  bool iuse_fourier
139  );
140 
145  (
146  double ivanishing_point_detection_success_probability,
147  double ioutlier_threshold_for_vanishing_points_assignment
148  );
149 
151  void read(std::istream& in);
152 
153  void read(const char* fname)
154  {
155  Readable::read(fname);
156  }
157 
159  void write(std::ostream& out) const;
160 
161  void write(const char* fname) const
162  {
163  Writeable::write(fname);
164  }
165 
167  inline const kjb::Edge_set & get_edges()
168  {
169  if(!_edges_available)
170  {
171  KJB_THROW_2(KJB_error,"Edges are not available!");
172  }
173  return *edges;
174  }
175 
178  {
179  if(!_edge_segments_available)
180  {
181  KJB_THROW_2(KJB_error,"Edge segments are not available!");
182  }
183  return *edge_segments;
184  }
185 
188  {
189  if(!_manhattan_world_available)
190  {
191  KJB_THROW_2(KJB_error,"Manhattan world is not available!");
192  }
193  return *manhattan_world;
194  }
195 
197  inline bool edges_available()
198  {
199  return _edges_available;
200  }
201 
204  {
205  return _edge_segments_available;
206  }
207 
210  {
211  return _manhattan_world_available;
212  }
213 
214  void set_manhattan_focal_length(double ifocal);
215 
217 
219  {
220  return outlier_threshold_for_vanishing_points_assignment;
221  }
222 
223  void remove_frame_segments();
224 
225  void reset_manhattan_world_vpts(const std::vector<Vanishing_point> & vpts, double focal)
226  {
227  manhattan_world->reset_vanishing_points(vpts);
228  manhattan_world->set_focal_length(focal);
229  manhattan_world->assign_segments_to_vpts(*edge_segments);
230  manhattan_world->create_corners();
231  }
232 
233  private:
234 
236  Features_manager(const Features_manager & src) :
237  Readable(), Writeable() { (*this) = src; }
238 
240  Features_manager & operator=(const Features_manager & /* src */)
241  {
242  return (*this);
243  }
244 
246  bool detect_features
247  (
248  bool idetect_edges,
249  bool ifit_edge_segments,
250  bool icreate_manhattan_world,
251  const kjb::Image & img
252  );
253 
255  bool detect_features
256  (
257  bool idetect_edges,
258  bool ifit_edge_segments,
259  bool icreate_manhattan_world,
260  const std::string & img_path
261  );
262 
264  void detect_edges(const kjb::Image & img);
265 
267  void fit_edge_segments_to_edges();
268 
271  bool create_manhattan_world(const kjb::Image & img);
272 
275  bool create_manhattan_world(const std::string & img_path);
276 
280  kjb::Edge_set * edges;
281 
283  Edge_segment_set * edge_segments;
284 
286  Manhattan_world * manhattan_world;
287 
289  bool _edges_available;
290 
292  bool _edge_segments_available;
293 
295  bool _manhattan_world_available;
296 
297 
298 
305  float blurring_sigma;
306 
309  float begin_threshold;
310 
313  float end_threshold;
314 
319  unsigned int padding;
320 
322  bool use_fourier;
323 
328  double vanishing_point_detection_success_probability;
329 
336  double outlier_threshold_for_vanishing_points_assignment;
337 
338 };
339 
340 Features_manager * detect_hoiem_features_manager
341 (
342  const std::string & img_path
343 );
344 
345 }
346 
347 #endif
Features_manager(std::istream &in)
Constructs a features manager by reading it from an input stream.
Definition: features_manager.h:107
Abstract class to write this object to an output stream.
Definition: l_writeable.h:41
void reset_vanishing_points(const std::vector< Vanishing_point > &vpts)
Definition: manhattan_world.h:527
Declarations for handling Manhattan world objects.
Features_manager(const char *filename)
Constructs a features manager by reading it from a file.
Definition: features_manager.h:116
void create_corners()
Creates corners by checking all possible intersections of two and three line segments.
Definition: manhattan_world.cpp:1290
Abstract class to read this object from an input stream.
Definition: l_readable.h:39
Features_manager(const kjb::Image &img, bool idetect_edges=true, bool ifit_edge_segments=true, bool icreate_manhattan_world=true)
Constructs a features manager. All options are set to default values All the requested features will ...
Definition: features_manager.cpp:43
void set_manhattan_focal_length(double ifocal)
Definition: features_manager.cpp:831
Definition: features_manager.h:55
const kjb::Edge_set & get_edges()
Returns a pointer to the edge set if available.
Definition: features_manager.h:167
void write(const char *fname) const
Writes this Writeable to a file.
Definition: features_manager.h:161
double get_outlier_threshold_for_vanishing_points_assignment()
Definition: features_manager.h:218
void set_manhattan_world_parameters(double ivanishing_point_detection_success_probability, double ioutlier_threshold_for_vanishing_points_assignment)
Sets the parameters needed to detect Manhattan world features (vanishing points for three orthogonal ...
Definition: features_manager.cpp:649
virtual void write(std::ostream &out) const =0
Writes this Writeable to an output stream.
#define FM_DEFAULT_VP_SUCCESS_PROBABILITY
Definition: features_manager.h:29
void remove_frame_segments()
Definition: features_manager.cpp:855
~Features_manager()
Definition: features_manager.h:124
bool edge_segments_available()
Returns true if edge segments are available.
Definition: features_manager.h:203
void write(std::ostream &out) const
Writes this Features_manager to an output stream.
Definition: features_manager.cpp:544
void reset_manhattan_world_vpts(const std::vector< Vanishing_point > &vpts, double focal)
Definition: features_manager.h:225
Declarations for Line segment set classes.
void set_edge_detection_parameters(float iblurring_sigma, float ibegin_threshold, float iend_threshold, unsigned int ipadding, bool iuse_fourier)
Sets the parameters needed for edge detection.
Definition: features_manager.cpp:602
Features_manager * detect_hoiem_features_manager(const std::string &img_path)
Definition: features_manager.cpp:864
void set_focal_length(double ifocal)
returns the focal length
Definition: manhattan_world.h:522
#define KJB_THROW_2(ex, msg)
Definition: l_exception.h:48
Manhattan_world & get_manhattan_world() const
Returns a pointer to Manhattan world if available.
Definition: features_manager.h:187
bool edges_available()
Returns true if edges are available.
Definition: features_manager.h:197
Exception often thrown when wrapped C functions return error codes.
Definition: l_exception.h:262
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
const Edge_segment_set & get_edge_segments()
Returns a pointer to the edge segments set if available.
Definition: features_manager.h:177
void assign_segments_to_vpts(const Edge_segment_set &, double outlier_threshold=MW_OUTLIER_THRESHOLD)
Assigns each input segment to the vanishing point it converges to, or mark it as an outlier if it doe...
Definition: manhattan_world.cpp:166
Definition: edge.h:233
virtual void read(std::istream &in)=0
Reads this Readable from an input stream.
Class to manipulate a set of edge segments.
Definition: line_segment_set.h:128
Support for error handling exception classes in libKJB.
Wrapped version of the C struct KJB_image.
Definition: i_image.h:76
bool manhattan_world_available()
Returns true if Manhattan world is available.
Definition: features_manager.h:209
void read(std::istream &in)
Reads this Features_manager from an input stream.
Definition: features_manager.cpp:256
void set_manhattan_world(Manhattan_world *mw)
Definition: features_manager.cpp:840
#define FM_DEFAULT_VP_ASSIGNMENT_THRESHOLD
Definition: features_manager.h:30
void read(const char *fname)
Reads this Readable from a file.
Definition: features_manager.h:153