15 #ifndef EDGE_MANHATTAN_WORLD_H
16 #define EDGE_MANHATTAN_WORLD_H
28 #define MW_OUTLIER_THRESHOLD 0.16
29 #define MAX_CORNER_SEGMENT_STRETCH 35
30 #define MAX_CORNER_PERP_SEGMENT_STRETCH 3
31 #define MW_FOCAL_INIT_VALUE 150
32 #define MW_MIN_FOCAL_INIT_VALUE 50
46 : _segment(isegment), _vp(ivp)
61 : _segment(src._segment), _vp(src._vp),
62 alpha(src.alpha), _outlier(src._outlier) { }
113 void draw(
kjb::Image & img,
double ir,
double ig,
double ib,
double width = 1.0)
const
115 _segment.
draw(img, ir, ig, ib, width);
131 #warning "[Code police] Please don't start identifiers with underscore."
160 double idist = 0.0,
double iperp_dist = 0.0) :
161 segment(isegment), distance_to_centre(idist), perpendicular_distance(iperp_dist)
168 segment(src.segment),
169 distance_to_centre(src.distance_to_centre),
170 perpendicular_distance(src.perpendicular_distance)
206 return distance_to_centre;
215 return perpendicular_distance;
228 distance_to_centre = src.distance_to_centre;
229 perpendicular_distance = src.perpendicular_distance;
233 const Manhattan_segment & segment;
235 double distance_to_centre;
237 double perpendicular_distance;
254 orthogonal_segments(3), v_pts(ivpts)
261 indexes(src.indexes), orthogonal_segments(src.orthogonal_segments), v_pts(src.v_pts)
263 for(
unsigned int i = 0;
i < 3;
i++)
274 available = src.available;
275 for(
unsigned int i = 0;
i < 3;
i++)
282 orthogonal_segments = src.orthogonal_segments;
284 position = src.position;
285 indexes = src.indexes;
291 for(
unsigned int i = 0;
i < 3;
i++)
341 if(iposition.
size() < 2)
345 position = iposition;
346 for(
unsigned int i =0;
i < 3;
i++)
390 available[
i] =
false;
400 return orthogonal_segments[
i];
405 void draw(
kjb::Image & img,
bool draw_full_segments =
false,
double width = 1.0)
const;
435 bool is_right_segment(
unsigned int i);
439 std::vector<Manhattan_corner_segment *> segments;
441 std::vector<bool> available;
443 std::vector<unsigned int> indexes;
445 std::vector<Line_segment> orthogonal_segments;
447 std::vector<Vanishing_point> * v_pts;
467 : _assignments(4), _vpts(ivpts), focal_length(ifocal)
473 if(ivpts.size() != 3)
486 read(filename, isegments, outlier_threshold);
498 read(in, isegments, outlier_threshold);
502 _corners2(src._corners2), _corners3(src._corners3),
503 _vpts(src._vpts), focal_length(src.focal_length) { }
507 _assignments = src._assignments;
509 _corners2 = src._corners2;
510 _corners3 = src._corners3;
511 focal_length = src.focal_length;
524 focal_length = ifocal;
530 for(
unsigned int i = 0;
i < 4;
i++)
532 _assignments[
i].clear();
544 const std::vector < std::vector<Manhattan_segment> > &
get_assignments()
const {
return _assignments; }
574 void read(
const char * filename);
575 void read(std::istream& in);
578 void write(std::ostream& out)
const;
581 void write(
const char * out_file)
const
583 std::ofstream ofs(out_file);
595 if(i >= _corners2.size())
605 if(i >= _corners3.size())
614 if(i >= _extra_corners.size())
618 return _extra_corners[
i];
681 bool check_consistency =
true
699 return _corners2.size();
704 return _corners3.size();
709 return _extra_corners.size();
749 return _extra_corners;
763 std::vector < std::vector<Manhattan_segment> > _assignments;
765 std::vector<Manhattan_corner> _corners2;
767 std::vector<Manhattan_corner> _corners3;
769 std::vector<Manhattan_corner> _extra_corners;
772 std::vector <Vanishing_point> _vpts;
778 std::ostream&
operator<<(std::ostream& out,
const Manhattan_corner& mc);
779 std::ostream &
operator<<(std::ostream& out,
const Manhattan_corner_segment& mcs);
780 std::ostream &
operator<<(std::ostream& out,
const Manhattan_segment& ms);
786 const std::string & file_name,
788 unsigned int num_rows,
789 unsigned int num_cols
void create_corners3()
Creates corners by checking all possible intersections of three line segments.
Definition: manhattan_world.cpp:1218
void draw_corners3smart(kjb::Image &img, bool draw_full_segments=false, double width=1.0) const
Definition: manhattan_world.cpp:760
void write(const char *out_file) const
Writes this Manhattan world to an output file.
Definition: manhattan_world.h:581
Definition: edge_segment.h:36
#define MW_FOCAL_INIT_VALUE
Definition: manhattan_world.h:31
double get_strength() const
returns the average gradient magnitude of this edge
Definition: edge_segment.h:135
void reset_vanishing_points(const std::vector< Vanishing_point > &vpts)
Definition: manhattan_world.h:527
void draw(kjb::Image &img, bool draw_full_segments=false, double width=1.0) const
Definition: manhattan_world.cpp:100
friend std::ostream & operator<<(std::ostream &out, const Manhattan_segment &ms)
Manhattan_corner_segment(const Manhattan_segment &isegment, double idist=0.0, double iperp_dist=0.0)
Definition: manhattan_world.h:159
void compute_orthogonal_segments()
Definition: manhattan_world.cpp:529
const Manhattan_corner_segment * get_segment(unsigned int i) const
Definition: manhattan_world.h:312
size_type size() const
Alias to get_length(). Required to comply with stl Container concept.
Definition: m_vector.h:510
void create_corners()
Creates corners by checking all possible intersections of two and three line segments.
Definition: manhattan_world.cpp:1290
~Manhattan_corner()
Definition: manhattan_world.h:289
#define MW_OUTLIER_THRESHOLD
Definition: manhattan_world.h:28
Manhattan_corner(const Manhattan_corner &src)
Definition: manhattan_world.h:259
void draw_corners3up(kjb::Image &img, bool draw_full_segments=false, double width=1.0) const
Definition: manhattan_world.cpp:968
Manhattan_world(const std::vector< Vanishing_point > &ivpts, double ifocal=MW_FOCAL_INIT_VALUE)
Definition: manhattan_world.h:466
const Manhattan_segment & get_manhattan_segment() const
Definition: manhattan_world.h:180
void set_index(unsigned int i, unsigned int iindex)
Definition: manhattan_world.h:374
unsigned int get_num_corners3() const
Definition: manhattan_world.h:702
void read(std::istream &in, const Edge_segment_set &isegments, double outlier_threshold=MW_OUTLIER_THRESHOLD)
Reads this Manhattan world from an input stream.
Definition: manhattan_world.cpp:284
static bool create_corner3(Manhattan_corner &corner, const Manhattan_segment &seg3, unsigned int index3, double max_stretch=MAX_CORNER_SEGMENT_STRETCH, double max_perp_stretch=MAX_CORNER_PERP_SEGMENT_STRETCH)
Creates a corner from an already existing corner and a line segment. Returns false if the segment doe...
Definition: manhattan_world.cpp:1046
void draw_corners2smart(kjb::Image &img, bool draw_full_segments=false, double width=1.0) const
Definition: manhattan_world.cpp:749
#define MAX_CORNER_PERP_SEGMENT_STRETCH
Definition: manhattan_world.h:30
Manhattan_world * create_manhattan_world_from_CMU_file(const std::string &file_name)
Definition: manhattan_world.cpp:1572
void randomly_color(kjb::Image &img, double width=1.0) const
Randomly colors this line segment on an image.
Definition: gr_line_segment.cpp:438
void draw_extra_corners(kjb::Image &img, bool draw_full_segments=false, double width=1.0) const
Definition: manhattan_world.cpp:771
Definition: manhattan_world.h:249
const std::vector< Manhattan_corner > & get_extra_corners() const
Definition: manhattan_world.h:747
const std::vector< Vanishing_point > get_value_vanishing_points() const
Definition: manhattan_world.h:552
A vanishing point for a set of parallel lines in an image.
Definition: vanishing_point.h:37
unsigned num_lines_assigned_to_vp(unsigned vpindex) const
returns the length of the vector of the segments assigned to the vanishing point
Definition: manhattan_world.h:547
#define MW_MIN_FOCAL_INIT_VALUE
Definition: manhattan_world.h:32
const Manhattan_corner & get_corner_3(unsigned int i) const
Returns the ith corner consisting of the intersection of three line segments.
Definition: manhattan_world.h:603
This class implements vectors, in the linear-algebra sense, with real-valued elements.
Definition: m_vector.h:87
double get_strength() const
Definition: manhattan_world.h:195
void draw_mid_point_to_vanishing_point(kjb::Image &img, double ir, double ig, double ib, double width=1.0) const
Draws a line between the line segment mid point and the vanishing point it converges to Mostly for de...
Definition: manhattan_world.cpp:43
void write_corners(std::ostream &out) const
Definition: manhattan_world.cpp:874
void init_missing_orthogonal_segment(int iindex, double start_x, double start_y, double end_x, double end_y)
Definition: manhattan_world.cpp:407
void set_segment(unsigned int i, const Manhattan_segment &segment, double dist=0.0, double perp_dist=0)
Definition: manhattan_world.h:363
void set_extra_corners_from_vertical_pairs(const std::vector< Segment_pair > &vpairs)
Definition: manhattan_world.cpp:1386
const Edge_segment & get_edge_segment() const
Definition: manhattan_world.h:185
void read_manhattan_corner(Manhattan_corner &corner, std::istream &in) const
Definition: manhattan_world.cpp:779
double get_least_squares_fitting_error() const
returns the sum of square residuals between the edge points and the fitted line segment.
Definition: edge_segment.h:129
Manhattan_segment(const Edge_segment &isegment, Vanishing_point *ivp=0)
Definition: manhattan_world.h:45
bool is_outlier() const
Returns true if this segment is an outlier, ie it is not aligned with one of the three orthogonal dir...
Definition: manhattan_world.h:99
Definition: manhattan_world.h:155
const Manhattan_segment & get_manhattan_segment(unsigned int vp_index, unsigned int segment_index) const
Definition: manhattan_world.cpp:247
void print_corners(std::ostream &out) const
Definition: manhattan_world.h:712
const kjb::Vector & get_position() const
Returns the position of the corner in the image plane.
Definition: manhattan_world.h:333
void write_manhattan_corner(const Manhattan_corner &corner, std::ostream &out) const
Definition: manhattan_world.cpp:729
double dist(const pt a, const pt b)
compute approx. Great Circle distance between two UTM points
Definition: layer.cpp:45
friend std::ostream & operator<<(std::ostream &out, const Manhattan_corner &mc)
void draw(kjb::Image &img, double ir, double ig, double ib, double width=1.0) const
Draws this line segment.
Definition: gr_line_segment.cpp:423
~Manhattan_corner_segment()
Definition: manhattan_world.h:175
Manhattan_world * create_mw_from_CMU_file_and_compute_focal_length(const std::string &file_name, const kjb::Edge_segment_set &iset, unsigned int num_rows, unsigned int num_cols)
Definition: manhattan_world.cpp:1581
friend std::ostream & operator<<(std::ostream &out, const Manhattan_corner_segment &mcs)
bool create_corner3_from_incomplete(Manhattan_corner &corner, unsigned int index3, bool towards_vp, const kjb::Vector &position, bool check_consistency=true)
Definition: manhattan_world.cpp:1076
const Line_segment & get_orthogonal_segment(unsigned int i) const
Definition: manhattan_world.h:394
void write(std::ostream &out) const
Writes this Manhattan world to an output stream.
Definition: manhattan_world.cpp:396
void delete_segment(unsigned int i)
Definition: manhattan_world.h:383
Declarations for Line segment set classes.
void randomly_color(kjb::Image &img, double width=1.0) const
Randomly colors this Manhattan segment on an image.
Definition: manhattan_world.h:119
Manhattan_world(const char *filename, const Edge_segment_set &isegments, double outlier_threshold=MW_OUTLIER_THRESHOLD)
Definition: manhattan_world.h:482
void draw_corners(kjb::Image &img, bool draw_full_segments=false, double width=1.0) const
Definition: manhattan_world.cpp:935
const std::vector< Manhattan_corner > & get_corners2() const
Definition: manhattan_world.h:742
~Manhattan_segment()
Definition: manhattan_world.h:110
Manhattan_corner_segment(const Manhattan_corner_segment &src)
Definition: manhattan_world.h:167
unsigned int get_num_corners2() const
Definition: manhattan_world.h:697
double get_perpendicular_distance() const
Definition: manhattan_world.h:213
const Manhattan_corner & get_extra_corner(unsigned int i) const
Definition: manhattan_world.h:612
void read_corners(std::istream &in)
Definition: manhattan_world.cpp:888
bool is_up_corner() const
Definition: manhattan_world.cpp:681
Manhattan_world(const char *filename)
Definition: manhattan_world.h:489
const std::vector< std::vector< Manhattan_segment > > & get_assignments() const
returns the vector of the segments assigned to the correct vanishing point (outliers in the last vect...
Definition: manhattan_world.h:544
void set_focal_length(double ifocal)
returns the focal length
Definition: manhattan_world.h:522
void set_vanishing_point(Vanishing_point *ivp)
Definition: manhattan_world.h:70
void draw_corners2up(kjb::Image &img, bool draw_full_segments=false, double width=1.0) const
Definition: manhattan_world.cpp:957
double get_distance() const
Definition: manhattan_world.h:204
void draw_corners3(kjb::Image &img, bool draw_full_segments=false, double width=1.0) const
Definition: manhattan_world.cpp:949
void mark_as_outlier()
Marks this segment as an outlier.
Definition: manhattan_world.h:88
std::ofstream & operator<<(std::ofstream &out, const Quaternion &q)
Definition: turntable_camera.cpp:77
Manhattan_corner operator=(const Manhattan_corner &src)
Definition: manhattan_world.h:272
#define KJB_THROW_2(ex, msg)
Definition: l_exception.h:48
void draw_lines_from_segments_midpoint_to_vp(kjb::Image &img, double width=1.0) const
Draws a line between the mid point of each segment (excluding outliers) and the vanishing point the s...
Definition: manhattan_world.cpp:200
unsigned int num_available_segments() const
Definition: manhattan_world.cpp:87
void create_corners2()
Creates corners by checking all possible intersections of two line segments.
Definition: manhattan_world.cpp:1145
Manhattan_world(double ifocal=MW_FOCAL_INIT_VALUE)
Definition: manhattan_world.h:464
bool is_available(unsigned int i) const
Returns true if the ith corner segment was detected in the image, false if it is missing.
Definition: manhattan_world.h:303
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
Manhattan_world & operator=(const Manhattan_world &src)
Definition: manhattan_world.h:505
const std::vector< Vanishing_point > & get_vanishing_points() const
Returns the vanishing points.
Definition: manhattan_world.h:550
Manhattan_world(const Manhattan_world &src)
Definition: manhattan_world.h:501
void get_3D_corner(double z_distance, double princ_x, double princ_y, unsigned int index, bool usecorner3, kjb::Vector &corner3D_1, kjb::Vector &corner3D_2, kjb::Vector &corner3D_3, kjb::Vector &position_3D) const
Definition: manhattan_world.cpp:1339
double get_focal_length() const
returns the focal length
Definition: manhattan_world.h:516
void set_segment(const Manhattan_corner_segment &segment, unsigned int i)
Definition: manhattan_world.h:352
void print_corners2(std::ostream &out) const
Definition: manhattan_world.cpp:1296
double get_avg_segment_size() const
Definition: manhattan_world.cpp:706
const Edge_segment & get_edge_segment() const
returns the edge segment defining this manhattan segment
Definition: manhattan_world.h:65
Object thrown when an argument to a function is not acceptable.
Definition: l_exception.h:377
void compute_orthogonal_segment(unsigned int i)
Definition: manhattan_world.cpp:413
const std::vector< Manhattan_corner > & get_corners3() const
Definition: manhattan_world.h:737
void print_vanishing_points(std::ostream &out) const
Definition: manhattan_world.cpp:1321
double get_fitting_error() const
Definition: manhattan_world.h:190
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
const Manhattan_corner & get_corner_2(unsigned int i) const
Returns the ith corner consisting of the intersection of two line segments.
Definition: manhattan_world.h:593
void print_corners3(std::ostream &out) const
Definition: manhattan_world.cpp:1305
Manhattan_segment(const Manhattan_segment &src)
Definition: manhattan_world.h:60
get the indices of edges in each direction for i
Definition: APPgetLargeConnectedEdges.m:48
Object thrown when input or output fails.
Definition: l_exception.h:496
static double compute_alpha(const kjb::Vanishing_point &vp, const Line_segment *line)
Compute the angle between the line segment and the line through the vanishing point and the line segm...
Definition: vanishing_point_detector.cpp:126
void draw_corners2(kjb::Image &img, bool draw_full_segments=false, double width=1.0) const
Definition: manhattan_world.cpp:941
double get_alpha() const
returns alpha
Definition: manhattan_world.h:105
Class to manipulate a set of edge segments.
Definition: line_segment_set.h:128
void draw_segments_with_vp_assignments(kjb::Image &img, double width=1.0) const
draws the line segments with different colors according to the vanishing point they are assigned to (...
Definition: manhattan_world.cpp:227
Wrapped version of the C struct KJB_image.
Definition: i_image.h:76
unsigned int get_index(unsigned int i) const
Returns the index in the edge_segments vector stored in the Manahattan_world class corresponding to t...
Definition: manhattan_world.h:323
void set_position(const kjb::Vector &iposition)
Sets the position of the corner in the image plane.
Definition: manhattan_world.h:339
unsigned int get_num_extra_corners() const
Definition: manhattan_world.h:707
double compute_penalty() const
Definition: manhattan_world.cpp:261
static bool create_corner(Manhattan_corner &corner, const Manhattan_segment &seg1, const Manhattan_segment &seg2, unsigned int index1, unsigned int index2, double max_stretch=MAX_CORNER_SEGMENT_STRETCH)
Creates a corner from two line segments. Returns false if the segments do not intersect.
Definition: manhattan_world.cpp:991
A manhattan segment defined by a line segment and the vanishing point it converges to...
Definition: manhattan_world.h:42
Class to manipulate a line segment The class is parametrized in terms the position of the centre...
Definition: gr_line_segment.h:62
void get_direction(unsigned int segment_index, kjb::Vector &direction) const
Definition: manhattan_world.cpp:664
const Vanishing_point * get_vanishing_point() const
Returns the vanishing point this Manhattan segment converges to.
Definition: manhattan_world.h:68
Manhattan_world(std::istream &in, const Edge_segment_set &isegments, double outlier_threshold=MW_OUTLIER_THRESHOLD)
Definition: manhattan_world.h:494
void draw(kjb::Image &img, double ir, double ig, double ib, double width=1.0) const
Draws this Manhattan segment.
Definition: manhattan_world.h:113
#define MAX_CORNER_SEGMENT_STRETCH
Definition: manhattan_world.h:29
void get_3D_corner(double z_distance, double focal_length, double princ_x, double princ_y, kjb::Vector &corner3D_1, kjb::Vector &corner3D_2, kjb::Vector &corner3D_3, kjb::Vector &position_3D) const
Definition: manhattan_world.cpp:538
Manhattan_corner(std::vector< Vanishing_point > *ivpts)
Definition: manhattan_world.h:252