contrib/gel/vmal/vmal_track_lines.h
Go to the documentation of this file.
00001 // This is gel/vmal/vmal_track_lines.h
00002 #ifndef vmal_track_lines_h_
00003 #define vmal_track_lines_h_
00004 //--------------------------------------------------------------------------------
00005 //:
00006 //  \file
00007 //
00008 //   Match lines that have been detected in a sequence of images. To achieve
00009 //   this, it uses the homographies between the images.
00010 //
00011 // \author
00012 //   L. Guichard
00013 // \verbatim
00014 // Modifications:
00015 //   Feb.2002 - Peter Vanroose - brief doxygen comment placed on single line
00016 // \endverbatim
00017 //--------------------------------------------------------------------------------
00018 #include <vcl_vector.h>
00019 #include <vxl_config.h>
00020 #include <vtol/vtol_edge_2d_sptr.h>
00021 #include <vmal/vmal_multi_view_data_edge_sptr.h>
00022 
00023 #include <vil1/vil1_image.h>
00024 #include <vil1/vil1_memory_image_of.h>
00025 
00026 #include <vnl/vnl_double_3x3.h>
00027 
00028 class vmal_track_lines
00029 {
00030  public:
00031 
00032 //***************************************************************************
00033 // Initialization
00034 //***************************************************************************
00035 
00036 //---------------------------------------------------------------------------
00037 //: Constructor.
00038 //---------------------------------------------------------------------------
00039   vmal_track_lines();
00040 //---------------------------------------------------------------------------
00041 //: Destructor.
00042 //---------------------------------------------------------------------------
00043   virtual ~vmal_track_lines();
00044 
00045 //---------------------------------------------------------------------------
00046 //: Main function that computes the matches between lines in the images.
00047 //---------------------------------------------------------------------------
00048   void track_lines(const vcl_vector<vcl_vector<vtol_edge_2d_sptr>*>* fit_lines,
00049                    const vcl_vector<vcl_vector<vtol_edge_2d_sptr>*>* transformed_lines,
00050                    const vcl_vector<vil1_image> &images, const vcl_vector<vnl_double_3x3> &homo,
00051                    vmal_multi_view_data_edge_sptr matches);
00052 
00053 //---------------------------------------------------------------------------
00054 //: Sort the input matches.
00055 // The first end-point of the first line of a match
00056 // must be linked to the corresponding end-point of the second line.
00057 //---------------------------------------------------------------------------
00058   void sort_lines(vmal_multi_view_data_edge_sptr matches,
00059                   vmal_multi_view_data_edge_sptr sorted_matches);
00060 
00061 //---------------------------------------------------------------------------
00062 //: Compute the correlation between two lines using the homography.
00063 // It also computes a translation vector to correct the error due to
00064 // the homography.
00065 //---------------------------------------------------------------------------
00066   double lines_correlation(vtol_edge_2d_sptr line0,
00067                            vtol_edge_2d_sptr line1,
00068                            const vnl_double_3x3 & H,
00069                            vil1_memory_image_of<vxl_byte> &image0,
00070                            vil1_memory_image_of<vxl_byte> &image1);
00071 
00072  private:
00073 
00074   double seg_angle(vtol_edge_2d_sptr, vtol_edge_2d_sptr);
00075   bool belong(vtol_edge_2d_sptr, vtol_edge_2d_sptr);
00076   double dist(vtol_edge_2d_sptr, vtol_edge_2d_sptr);
00077 //-----------------------------------------------------------------------------
00078 //: Project the point (x0,y0) on the line ((ax,ay),(bx,by)).
00079 // The resulting projected point is (x,y).
00080 // It also returns the distance between the line and the projected point.
00081 // If (x,y) does not belong to the segment [(ax,ay),(bx,by)], sets (x,y) to (-1,-1).
00082 //-----------------------------------------------------------------------------
00083   double project_point(double x0,double y0,
00084                        double ax,double ay,
00085                        double bx,double by,
00086                        double *x,double *y);
00087 
00088   int is_cur_best(vtol_edge_2d_sptr trans_line,vtol_edge_2d_sptr fitted_line,vtol_edge_2d_sptr other_line);
00089 //-----------------------------------------------------------------------------
00090 //: Find the transformed of line.
00091 //-----------------------------------------------------------------------------
00092   vtol_edge_2d_sptr find_transfo(vtol_edge_2d_sptr line,
00093                                  vcl_vector<vtol_edge_2d_sptr>& fit_lines,
00094                                  const vcl_vector<vtol_edge_2d_sptr>& transformed_lines);
00095 //-----------------------------------------------------------------------------
00096 //: Compute two new lines by comparing the input lines and keeping their common part through the homography
00097 //-----------------------------------------------------------------------------
00098   void refine_line_at_min(vtol_edge_2d_sptr line0, vtol_edge_2d_sptr line1,
00099                           vtol_edge_2d_sptr &new_line0, vtol_edge_2d_sptr &new_line1,
00100                           const vnl_double_3x3 &H);
00101 
00102   void sort_a_pair_of_line(vtol_edge_2d_sptr line0,
00103                            vtol_edge_2d_sptr line1,
00104                            vtol_edge_2d_sptr &new_line0,
00105                            vtol_edge_2d_sptr &new_line1);
00106 
00107 
00108   void cost_function(vtol_edge_2d_sptr line0,
00109                      vtol_edge_2d_sptr t_line0,
00110                      vtol_edge_2d_sptr line1,
00111                      const vil1_image &image0, const vil1_image &image1,
00112                      const vnl_double_3x3 homo,
00113                      double &result);
00114 
00115   double theta_;
00116   double radius_;
00117 };
00118 
00119 #endif // vmal_track_lines_h_