KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
kjb::Vanishing_point_detector Class Reference

This class computes the position of the three vanishing points from a set of line segments. The ass. More...

#include <vanishing_point_detector.h>

Public Types

enum  { VPD_HORIZONTAL_VP_1 = 0, VPD_HORIZONTAL_VP_2, VPD_VERTICAL_VP, VPD_OUTLIER }
 

Public Member Functions

 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)
 
 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)
 
 Vanishing_point_detector (const Vanishing_point_detector &src)
 
Vanishing_point_detectoroperator= (const Vanishing_point_detector &src)
 
 ~Vanishing_point_detector ()
 
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. More...
 
void init_from_edge_segment_set (const Line_segment_set &iset, double vertical_threshold)
 Inits the edge segment that will be used to estimate the vanishing points. More...
 
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. More...
 
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. More...
 
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)
 
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. More...
 
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 points (v1, v2) v1'*w*v2 equals to zero, where w is the absolute conic. It then retrieves the principal point and focal length from W and tests that the principal point is not too far from the image centre and the focal length is positive. Returns false if any of these checks fails. More...
 
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)
 
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. More...
 
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. More...
 
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. More...
 
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 estimate of the vertical vanishing point. More...
 
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. More...
 
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)
 
bool get_use_relaxed_checks () const
 Sets the type of geometric constraints to be used. More...
 
void set_use_relaxed_checks (bool icheck)
 Returns true if realxed checks are used. More...
 
double compute_focal_length (const std::vector< Vanishing_point > &v_pts)
 Computes the focal length from the vanishing points position. More...
 
bool guess_horizontal_vpts_from_two_segments (Vanishing_point &vp1, Vanishing_point &vp2)
 
bool guess_horizontal_vpts_from_three_segments (Vanishing_point &vp1, Vanishing_point &vp2)
 
int get_tot_num_segments ()
 
void set_vpts_tolerance (double ivpts_tolerance)
 
double geometric_find_vpts_with_ransac (double success_probability, double outlier_threshold, double max_outliers_ratio, std::vector< Vanishing_point > &vpts)
 
double get_best_focal ()
 
int get_num_vertical_segments () const
 

Static Public Member Functions

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 segment mid point. More...
 
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] More...
 

Public Attributes

enum
kjb::Vanishing_point_detector:: { ... }  
Vanishing_point_index
 

Detailed Description

This class computes the position of the three vanishing points from a set of line segments. The ass.

Member Enumeration Documentation

anonymous enum
Enumerator
VPD_HORIZONTAL_VP_1 
VPD_HORIZONTAL_VP_2 
VPD_VERTICAL_VP 
VPD_OUTLIER 

Constructor & Destructor Documentation

kjb::Vanishing_point_detector::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 
)
inline
kjb::Vanishing_point_detector::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 
)
inline
kjb::Vanishing_point_detector::Vanishing_point_detector ( const Vanishing_point_detector src)
inline
kjb::Vanishing_point_detector::~Vanishing_point_detector ( )
inline

Member Function Documentation

bool Vanishing_point_detector::check_vpts_consistency ( const Vanishing_point vp1,
const Vanishing_point vp2,
const Vanishing_point vertical_vp,
double &  ifocal_length 
)

Checks that a set of three vanishing points is consistent. It checks that for each pair of vanishing points (v1, v2) v1'*w*v2 equals to zero, where w is the absolute conic. It then retrieves the principal point and focal length from W and tests that the principal point is not too far from the image centre and the focal length is positive. Returns false if any of these checks fails.

Checks that a set of three vanishing points is consistent. It checks that for each pair of vanishing points (v1, v2) v1'*w*v2 equals to zero, where w is the absolute conic. It then retrieves the principal point and focal length from W and tests that the principal point is not too far from the image centre and the focal length is positive. Returns false if any of these checks fails.

Parameters
vp1the first horizontal vanishing point
vp2the second horizontal vanishing point
vertical_vpthe vertical vanishing point
ifocal_lengthwill contain the focal length estimated from the vanishing points
double Vanishing_point_detector::compute_alpha ( const kjb::Vanishing_point vp,
const Line_segment edge_segment 
)
static

Compute the angle between the line segment and the line through the vanishing point and the line segment mid point.

Computes the angle between a edge segment and the line between a segment's mid point and a vanishing point

Parameters
vpthe vanishing point
edge_segmentthe edge segment
double Vanishing_point_detector::compute_focal_length ( const std::vector< Vanishing_point > &  v_pts)

Computes the focal length from the vanishing points position.

Computes the focal length from a set of three input vanishing points

Parameters
v_ptsThe input vanishing points
double Vanishing_point_detector::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.

Computes the RANSAC penalty for non vertical segments. Each edge segment is assigned to the vanishing point that minimizes the angle alpha between the edge segment and the line between the edge segment mid point and the vanishing point, and the angle alpha contributes to the total penalty, unless it is bigger than the input threshold

Parameters
outlier_thresholdThe threshold above which an edge segment is considered an outlier
total_number_of_outliersWill store the number of edge segments labeled as outliers
vp1This is the first horizontal vanishing point for which we have to compute the penalty
vp2This is the second horizontal vanishing point for which we have to compute the penalty
double Vanishing_point_detector::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.

Computes the RANSAC penalty for vertical segments. Each vertical segment contributes to the penalty proportionally to the angle alpha between the segment and the line between its midpoint and the vertical vanishing point

Parameters
outlier_thresholdThe threshold above which an edge segment is considered an outlier
total_number_of_outliersWill store the number of edge segments labeled as outliers
vertical_vpThe vertical vanishing point to be used to compute the penalty
bool Vanishing_point_detector::find_horizontal_vanishing_vpts_with_ransac ( double  success_probability,
double  outlier_threshold,
double  max_outliers_ratio,
const Vanishing_point vp_vertical,
Vanishing_point vp1,
Vanishing_point vp2 
)

Finds an estimate for the two horizontal vanishing points. IMPORTANT: It relies on the current estimate of the vertical vanishing point.

Find the two horizontal vanishing points using RANSAC from the horizontal line segments

Parameters
success_probabilityThe probability of finding the right solution This will increase or decrease the number of Ransac iterations. This does not necessarily do what you expect, because the ratio of inliers to outliers needed to compute the number of iterations from this probability is only an estimate It is wise to run RANSAC a little longer than you would think, since very few lines will intersect exactly at their vanishing point due to noise, and if we don't run it long enough we may get a vanishing point that is a little off its correct position
outlier_thresholdThe threshold above which a line segment is considered an outlier (ie it does not converge to any of the 3 vanishing points). It is the maximun difference in orientation allowed between the line segment and the segment between the midpoint of the segment and the vanishing point (in radian)
max_outliers_ratioThe maximum ratio between outliers and total segments allowed (ie 0.45 means that no more than 45% of the segments can be outliers)
bool Vanishing_point_detector::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.

Find the vertical vanishing point from the vertical segments using RANSAC

Parameters
success_probabilityThe probability of finding the right solution This will increase or decrease the number of Ransac iterations. This does not necessarily do what you expect, because the ratio of inliers to outliers needed to compute the number of iterations from this probability is only an estimate It is wise to run RANSAC a little longer than you would think, since very few lines will intersect exactly at their vanishing point due to noise, and if we don't run it long enough we may get a vanishing point that is a little off its correct position
outlier_thresholdThe threshold above which a line segment is considered an outlier (ie it does not converge to any of the 3 vanishing points). It is the maximun difference in orientation allowed between the line segment and the segment between the midpoint of the segment and the vanishing point (in radian)
max_outliers_ratioThe maximum ratio between outliers and total segments allowed (ie 0.45 means that no more than 45% of the segments can be outliers)
vpThis will contain the estimated vertical vanishing point
double Vanishing_point_detector::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 
)
double Vanishing_point_detector::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.

Find all the three vanishing points using RANSAC

Parameters
success_probabilityThe probability of finding the right solution This will increase or decrease the number of Ransac iterations. This does not necessarily do what you expect, because the ratio of inliers to outliers needed to compute the number of iterations from this probability is only an estimate It is wise to run RANSAC a little longer than you would think, since very few lines will intersect exactly at their vanishing point due to noise, and if we don't run it long enough we may get a vanishing point that is a little off its correct position
outlier_thresholdThe threshold above which a line segment is considered an outlier (ie it does not converge to any of the 3 vanishing points). It is the maximun difference in orientation allowed between the line segment and the segment between the midpoint of the segment and the vanishing point (in radian)
max_outliers_ratioThe maximum ratio between outliers and total segments allowed (ie 0.45 means that no more than 45% of the segments can be outliers)
vptsThis will contain the three estimated vanishing point, the last being the vertical
vp_outlier_thresholdequivalent to outlier_threshold, but this is used for the computation of the vertical vanishing point only
vertical_vp_max_outliers_ratioequivalent to max_outliers_ratio, but this is used only for the estimation of the vertical vanishing point
double Vanishing_point_detector::geometric_find_vpts_with_ransac ( double  success_probability,
double  outlier_threshold,
double  max_outliers_ratio,
std::vector< Vanishing_point > &  vpts 
)
double kjb::Vanishing_point_detector::get_best_focal ( )
inline
int kjb::Vanishing_point_detector::get_num_vertical_segments ( ) const
inline
int Vanishing_point_detector::get_tot_num_segments ( )
bool kjb::Vanishing_point_detector::get_use_relaxed_checks ( ) const
inline

Sets the type of geometric constraints to be used.

bool Vanishing_point_detector::groundtruth_check_vpts_consistency ( const Vanishing_point vp1,
const Vanishing_point vp2,
const Vanishing_point vertical_vp,
double &  ifocal_length,
double &  opx,
double &  opy 
)
double Vanishing_point_detector::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 
)
bool Vanishing_point_detector::guess_horizontal_vpts_from_three_segments ( Vanishing_point vp1,
Vanishing_point vp2 
)

If only three line segments are available, we assume that one vp is at the intersection of two of them, while the third segment converges to the other vp

bool Vanishing_point_detector::guess_horizontal_vpts_from_two_segments ( Vanishing_point vp1,
Vanishing_point vp2 
)

If only two line segments are available, we assume that each of them converges to a different vanishing point

void Vanishing_point_detector::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.

Init this vanishing point detector from the input segments. Only segments whose fitting error is reasonably small will be kept. Segments will be divided into two different classes according to their slope (vertical and non vertical, the former will be used to estimate the vertical vanishing point).

Parameters
vertical_thresholdSegments whose slope is larger than this threshold will be labeled as vertical segments
isetthe set of edge segments
max_line_segment_fitting_erroronly segments whose fitting error is smaller than this threshold will be used
void Vanishing_point_detector::init_from_edge_segment_set ( const Line_segment_set iset,
double  vertical_threshold 
)

Inits the edge segment that will be used to estimate the vanishing points.

Init this vanishing point detector from the input segments. Only segments whose fitting error is reasonably small will be kept. Segments will be divided into two different classes according to their slope (vertical and non vertical, the former will be used to estimate the vertical vanishing point).

Parameters
vertical_thresholdSegments whose slope is larger than this threshold will be labeled as vertical segments
isetthe set of edge segments
max_line_segment_fitting_erroronly segments whose fitting error is smaller than this threshold will be used
double Vanishing_point_detector::jointly_compute_ransac_penalty ( double  outlier_threshold,
double *  total_number_of_outliers,
double  max_outlier_threshold,
const Vanishing_point vp1,
const Vanishing_point vp2,
const Vanishing_point vp3 
)

Computes the RANSAC penalty for all segments given the three vanishing points.

Computes the RANSAC penalty for non vertical segments. Each edge segment is assigned to the vanishing point that minimizes the angle alpha between the edge segment and the line between the edge segment mid point and the vanishing point, and the angle alpha contributes to the total penalty, unless it is bigger than the input threshold

Parameters
outlier_thresholdThe threshold above which an edge segment is considered an outlier
total_number_of_outliersWill store the number of edge points labeled as outliers. Notice that this is edge points, not segments. This encourages the use of long segments
vp1This is the first horizontal vanishing point for which we have to compute the penalty
vp2This is the second horizontal vanishing point for which we have to compute the penalty
vp3This is the vertical vanishing point for which we have to compute the penalty
double Vanishing_point_detector::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.

Vanishing_point_detector& kjb::Vanishing_point_detector::operator= ( const Vanishing_point_detector src)
inline
bool Vanishing_point_detector::relaxed_check_vpts_consistency ( const Vanishing_point vp1,
const Vanishing_point vp2,
const Vanishing_point vertical_vp,
double &  ifocal_length 
)

Checks that a set of three vanishing points is consistent, using basic geometric constraints. For a more thourough check use check_vpts_consistency.

Checks that a set of three vanishing points is consistent, using basic geometric constraints. This is mostly for debug purposes, or for specific applications. For a thorough check use check_vpts_consistency.

Parameters
vp1the first horizontal vanishing point
vp2the second horizontal vanishing point
vertical_vpthe vertical vanishing point
ifocal_lengthwill contain the focal length estimated from the vanishing points
void Vanishing_point_detector::sample_n_from_m_without_repetitions ( unsigned int  n,
unsigned int  m,
Int_vector iv 
)
static

samples n integers without repetitions from the set [0,m]

void kjb::Vanishing_point_detector::set_use_relaxed_checks ( bool  icheck)
inline

Returns true if realxed checks are used.

void kjb::Vanishing_point_detector::set_vpts_tolerance ( double  ivpts_tolerance)
inline

Member Data Documentation

enum { ... } kjb::Vanishing_point_detector::Vanishing_point_index

The documentation for this class was generated from the following files: