21 #ifndef VANISHING_POINT_DETECTION_H
22 #define VANISHING_POINT_DETECTION_H
25 #include "i/i_float.h"
27 #include "edge/edge_base.h"
36 #define VPD_VERTICAL_THRESHOLD 0.12
37 #define VPD_VERTICAL_VP_OUTLIER_THRESHOLD 0.05
38 #define VPD_VERTICAL_VP_MAX_OUTLIERS_RATIO 0.6
40 #define VPD_MAX_LINE_SEGMENT_FITTING_ERROR 0.5
41 #define VPD_RANSAC_ROBUST_SUCCESS_PROBABILITY 0.998
47 #define VPD_MAX_PRINCIPAL_POINT_POSITION_TOLERANCE 18
48 #define VPD_LOOSE_VPTS_TOLERANCE 60
74 : _num_rows(img_rows), _num_cols(img_cols), use_relaxed_checks(false),
75 vpts_tolerance(ivpts_tolerance), A(3, 4, 1.0), Atranspose(0),
76 AA(0), absolute_conic(3,3,0.0), E_mp(0), D_vp(0),
77 decomposition(0), inverse(0)
80 kjb_c::get_target_matrix( &E_mp, 4, 4 );
81 kjb_c::get_target_matrix( &Atranspose, 4, 3 );
82 kjb_c::get_target_matrix( &AA, 4, 4 );
83 kjb_c::get_target_vector( &D_vp, 4);
89 : _num_rows(img_rows), _num_cols(img_cols), use_relaxed_checks(false),
90 vpts_tolerance(ivpts_tolerance), A(3, 4, 1.0), Atranspose(0),
91 AA(0), absolute_conic(3,3,0.0), E_mp(0), D_vp(0),
92 decomposition(0), inverse(0)
95 kjb_c::get_target_matrix( &E_mp, 4, 4 );
96 kjb_c::get_target_matrix( &Atranspose, 4, 3 );
97 kjb_c::get_target_matrix( &AA, 4, 4 );
98 kjb_c::get_target_vector( &D_vp, 4);
102 : _vertical_segments(src._vertical_segments), _regular_segments(src._regular_segments),
103 _num_rows(src._num_rows), _num_cols(src._num_cols), use_relaxed_checks(src.use_relaxed_checks),
104 vpts_tolerance(src.vpts_tolerance),
105 A(src.A), Atranspose(0), AA(0), absolute_conic(src.absolute_conic), E_mp(0), D_vp(0),
106 decomposition(0), inverse(0)
108 kjb_c::copy_matrix( &E_mp, src.E_mp);
109 kjb_c::copy_vector( &D_vp, src.D_vp);
110 kjb_c::copy_matrix( &decomposition, src.decomposition);
111 kjb_c::copy_matrix( &inverse, src.inverse);
112 kjb_c::copy_matrix( &Atranspose, src.Atranspose);
113 kjb_c::copy_matrix( &AA, src.AA);
119 _vertical_segments = src._vertical_segments;
120 _regular_segments = src._regular_segments;
121 _num_rows = src._num_rows;
122 _num_cols = src._num_cols;
123 use_relaxed_checks = src.use_relaxed_checks;
124 vpts_tolerance = src.vpts_tolerance;
126 absolute_conic = src.absolute_conic;
127 kjb_c::copy_matrix( &E_mp, src.E_mp);
128 kjb_c::copy_vector( &D_vp, src.D_vp);
129 kjb_c::copy_matrix( &decomposition, src.decomposition);
130 kjb_c::copy_matrix( &inverse, src.inverse);
131 kjb_c::copy_matrix( &Atranspose, src.Atranspose);
132 kjb_c::copy_matrix( &AA, src.AA);
141 kjb_c::free_vector(D_vp);
148 double max_line_segment_fitting_error );
164 double outlier_threshold,
165 unsigned int * total_number_of_outliers,
175 double outlier_threshold,
176 double * total_number_of_outliers,
177 double max_outliers_ratio,
185 double outlier_threshold,
186 int * total_number_of_outliers,
200 double outlier_threshold,
201 unsigned int * total_number_of_outliers,
219 double & focal_length
227 double & ifocal_length,
240 double & focal_length
246 double success_probability,
247 double outlier_threshold,
248 double max_outliers_ratio,
249 std::vector<Vanishing_point> & vpts,
257 double success_probability,
258 double outlier_threshold,
259 double max_outliers_ratio,
269 double success_probability,
270 double outlier_threshold,
271 double max_outliers_ratio,
280 double success_probability,
281 double outlier_threshold,
282 double max_outliers_ratio,
283 std::vector<Vanishing_point> & vpts
288 double outlier_threshold,
292 std::vector<Vanishing_point> & vpts
298 return use_relaxed_checks;
304 use_relaxed_checks = icheck;
325 vpts_tolerance = ivpts_tolerance;
330 double success_probability,
331 double outlier_threshold,
332 double max_outliers_ratio,
333 std::vector<Vanishing_point> & vpts
343 return _vertical_segments.size();
349 void insert_penalty_into_list(
double ipenalty);
351 double compute_average_inlier_penalty(
double outlier_threshold);
354 std::vector<const Line_segment *> _vertical_segments;
357 std::vector<const Line_segment *> _regular_segments;
360 unsigned int _num_rows;
363 unsigned int _num_cols;
367 bool use_relaxed_checks;
370 std::list<double> penalties;
372 double vpts_tolerance;
380 kjb_c::Matrix * Atranspose;
384 kjb_c::Matrix * E_mp;
385 kjb_c::Vector * D_vp;
386 kjb_c::Matrix * decomposition;
387 kjb_c::Matrix * inverse;
400 std::vector<Vanishing_point> & vpts,
401 double & focal_length,
404 bool jointly_estimate =
false,
405 std::vector<Vanishing_point> right_ones = std::vector<Vanishing_point>(0)
410 Vanishing_point & vertical,
422 std::vector<Vanishing_point> & vpts,
423 double & focal_length,
425 double success_probability
442 double outlier_threshold,
443 const Line_segment * isegment,
444 const std::vector<Vanishing_point> & ivpts
449 std::vector<Vanishing_point> & vpts,
450 double & focal_length,
452 const Line_segment_set & kovesi,
453 double start_threshold = 0.05,
460 std::vector<Vanishing_point> & vpts,
461 double & focal_length,
462 const std::string & img_path
bool check_vpts_consistency(const Vanishing_point &vp1, const Vanishing_point &vp2, const Vanishing_point &vertical_vp, double &focal_length)
Checks that a set of three vanishing points is consistent. It checks that for each pair of vanishing ...
Definition: vanishing_point_detector.cpp:1090
This class computes the position of the three vanishing points from a set of line segments...
Definition: vanishing_point_detector.h:59
void set_use_relaxed_checks(bool icheck)
Returns true if realxed checks are used.
Definition: vanishing_point_detector.h:302
void set_vpts_tolerance(double ivpts_tolerance)
Definition: vanishing_point_detector.h:323
bool groundtruth_check_vpts_consistency(const Vanishing_point &vp1, const Vanishing_point &vp2, const Vanishing_point &vertical_vp, double &ifocal_length, double &opx, double &opy)
Definition: vanishing_point_detector.cpp:1356
double find_vpts_with_ransac(double success_probability, double outlier_threshold, double max_outliers_ratio, std::vector< Vanishing_point > &vpts, double vertical_vp_outlier_threshold=VPD_VERTICAL_VP_OUTLIER_THRESHOLD, double vertical_vp_max_outliers_ratio=VPD_VERTICAL_VP_MAX_OUTLIERS_RATIO)
Finds an estimate for all three vanishing points using RANSAC.
Definition: vanishing_point_detector.cpp:477
bool find_vertical_vp_with_ransac(double success_probability, double outlier_threshold, double max_outliers_ratio, Vanishing_point &vp)
Finds an estimate for the vertical vanishing point.
Definition: vanishing_point_detector.cpp:774
A vanishing point for a set of parallel lines in an image.
Definition: vanishing_point.h:37
bool relaxed_vanishing_point_estimation(std::vector< Vanishing_point > &vpts, double &focal_length, const kjb::Image &img, double success_probability)
This function uses less constraints coming from geometry and uses the data more, relying on the assum...
Definition: vanishing_point_detector.cpp:2439
double get_best_focal()
Definition: vanishing_point_detector.h:336
bool robustly_estimate_vanishing_points(std::vector< Vanishing_point > &vpts, double &focal_length, const kjb::Image &img, double success_probability=VPD_RANSAC_ROBUST_SUCCESS_PROBABILITY, bool jointly_estimate=false, std::vector< Vanishing_point > right_ones=std::vector< Vanishing_point >(0))
Estimates the vanishing points for the three orthogonal directions of a Manhattan world scene (where ...
Definition: vanishing_point_detector.cpp:2199
double compute_focal_length(const std::vector< Vanishing_point > &v_pts)
Computes the focal length from the vanishing points position.
Definition: vanishing_point_detector.cpp:1845
double groundtruth_compute_ransac_penalty(double outlier_threshold, int *total_number_of_outliers, const Line_segment_set &vertical_bucket, const Line_segment_set &horizontal_bucket1, const Line_segment_set &horizontal_bucket2, const Vanishing_point &vp1, const Vanishing_point &vp2, const Vanishing_point &vp3)
Definition: vanishing_point_detector.cpp:329
#define VPD_RANSAC_ROBUST_SUCCESS_PROBABILITY
Definition: vanishing_point_detector.h:41
Definition: vanishing_point_detector.h:64
bool detect_vanishing_points(std::vector< Vanishing_point > &vpts, double &focal_length, const std::string &img_path)
Definition: vanishing_point_detector.cpp:2704
enum kjb::Vanishing_point_detector::@0 Vanishing_point_index
double jointly_find_vpts_with_ransac(double success_probability, double outlier_threshold, double max_outliers_ratio, std::vector< Vanishing_point > &vpts)
Finds an estimate of the three vanishing points at once.
Definition: vanishing_point_detector.cpp:505
void init_from_edge_segment_set(const Edge_segment_set &iset, double vertical_threshold, double max_line_segment_fitting_error)
Inits the edge segment that will be used to estimate the vanishing points.
Definition: vanishing_point_detector.cpp:1884
Class to manipulate a set of line segments.
Definition: line_segment_set.h:28
Declarations for Line segment set classes.
Definition: vanishing_point_detector.h:66
Vanishing_point_detector & operator=(const Vanishing_point_detector &src)
Definition: vanishing_point_detector.h:117
Definition: vanishing_point_detector.h:67
bool get_use_relaxed_checks() const
Sets the type of geometric constraints to be used.
Definition: vanishing_point_detector.h:296
This class implements vectors, in the linear-algebra sense, restricted to integer-valued elements...
Definition: l_int_vector.h:83
Definition: vanishing_point_detector.h:65
bool relaxed_check_vpts_consistency(const Vanishing_point &vp1, const Vanishing_point &vp2, const Vanishing_point &vertical_vp, double &focal_length)
Checks that a set of three vanishing points is consistent, using basic geometric constraints. For a more thourough check use check_vpts_consistency.
Definition: vanishing_point_detector.cpp:1585
Vanishing_point_detector(const Line_segment_set &iset, unsigned int img_rows, unsigned int img_cols, double vertical_threshold=VPD_VERTICAL_THRESHOLD, double ivpts_tolerance=VPD_MAX_PRINCIPAL_POINT_POSITION_TOLERANCE)
Definition: vanishing_point_detector.h:86
~Vanishing_point_detector()
Definition: vanishing_point_detector.h:136
unsigned int assign_to_vanishing_point(double outlier_threshold, const Line_segment *isegment, const std::vector< Vanishing_point > &ivpts)
Assigns an edge segments to the vanishing point that minimizes the angle between the segment and the ...
Definition: vanishing_point_detector.cpp:2524
#define VPD_MAX_LINE_SEGMENT_FITTING_ERROR
Definition: vanishing_point_detector.h:40
double compute_ransac_penalty(double outlier_threshold, unsigned int *total_number_of_outliers, const Vanishing_point &vp1, const Vanishing_point &vp2)
Computes the RANSAC penalty for the horizontal segments given the input horizontal vanishing points...
Definition: vanishing_point_detector.cpp:200
bool guess_horizontal_vpts_from_three_segments(Vanishing_point &vp1, Vanishing_point &vp2)
Definition: vanishing_point_detector.cpp:2005
double jointly_compute_ransac_penalty(double outlier_threshold, double *total_number_of_outliers, double max_outliers_ratio, const Vanishing_point &vp1, const Vanishing_point &vp2, const Vanishing_point &vp3)
Computes the RANSAC penalty for all segments given the three vanishing points.
Definition: vanishing_point_detector.cpp:257
Vanishing_point_detector(const Edge_segment_set &iset, unsigned int img_rows, unsigned int img_cols, double vertical_threshold=VPD_VERTICAL_THRESHOLD, double max_line_segment_fitting_error=VPD_MAX_LINE_SEGMENT_FITTING_ERROR, double ivpts_tolerance=VPD_MAX_PRINCIPAL_POINT_POSITION_TOLERANCE)
Definition: vanishing_point_detector.h:70
Vanishing_point_detector(const Vanishing_point_detector &src)
Definition: vanishing_point_detector.h:101
double find_vpts_from_groundtruth_assignments(double outlier_threshold, const Line_segment_set &vertical_bucket, const Line_segment_set &horizontal_bucket1, const Line_segment_set &horizontal_bucket2, std::vector< Vanishing_point > &vpts)
Definition: vanishing_point_detector.cpp:2769
bool find_horizontal_vanishing_vpts_with_ransac(double success_probability, double outlier_threshold, double max_outliers_ratio, const Vanishing_point &vertical_vp, Vanishing_point &vp1, Vanishing_point &vp2)
Finds an estimate for the two horizontal vanishing points. IMPORTANT: It relies on the current estima...
Definition: vanishing_point_detector.cpp:1707
void free_matrix(float **m, long nrl, long nrh, long ncl, long nch)
Definition: nr.cpp:237
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
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.
#define VPD_VERTICAL_VP_OUTLIER_THRESHOLD
Definition: vanishing_point_detector.h:37
int get_tot_num_segments()
Definition: vanishing_point_detector.cpp:397
for m
Definition: APPgetLargeConnectedEdges.m:64
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
double robustly_estimate_vanishing_points_Kovesi(std::vector< Vanishing_point > &vpts, double &focal_length, const Image &img, const Line_segment_set &kovesi, double start_threshold=0.05, double vpts_tolerance=VPD_MAX_PRINCIPAL_POINT_POSITION_TOLERANCE, double success_probability=VPD_RANSAC_ROBUST_SUCCESS_PROBABILITY)
Definition: vanishing_point_detector.cpp:2319
#define VPD_MAX_PRINCIPAL_POINT_POSITION_TOLERANCE
Definition: vanishing_point_detector.h:47
bool robustly_estimate_vertical_vanishing_point(Vanishing_point &vertical, const kjb::Image &img, double success_probability=VPD_RANSAC_ROBUST_SUCCESS_PROBABILITY)
Definition: vanishing_point_detector.cpp:2609
int get_num_vertical_segments() const
Definition: vanishing_point_detector.h:341
double geometric_find_vpts_with_ransac(double success_probability, double outlier_threshold, double max_outliers_ratio, std::vector< Vanishing_point > &vpts)
Definition: vanishing_point_detector.cpp:885
static void sample_n_from_m_without_repetitions(unsigned int n, unsigned int m, Int_vector &iv)
samples n integers without repetitions from the set [0,m]
Definition: vanishing_point_detector.cpp:2085
#define VPD_VERTICAL_VP_MAX_OUTLIERS_RATIO
Definition: vanishing_point_detector.h:38
Class to manipulate a line segment The class is parametrized in terms the position of the centre...
Definition: gr_line_segment.h:62
double compute_vertical_ransac_penalty(double outlier_threshold, unsigned int *total_number_of_outliers, const Vanishing_point &vertical_vp)
Computes the RANSAC penalty for the vertical segments given the input vertical vanishing point...
Definition: vanishing_point_detector.cpp:414
bool guess_horizontal_vpts_from_two_segments(Vanishing_point &vp1, Vanishing_point &vp2)
Definition: vanishing_point_detector.cpp:1979
#define VPD_VERTICAL_THRESHOLD
Definition: vanishing_point_detector.h:36