contrib/gel/vmal/vmal_rectifier.h
Go to the documentation of this file.
00001 // This is gel/vmal/vmal_rectifier.h
00002 #ifndef vmal_rectifier_h_
00003 #define vmal_rectifier_h_
00004 //--------------------------------------------------------------------------------
00005 //:
00006 // \file
00007 //
00008 //  Take a set of matched points and matched lines into 2 images
00009 //  and transform them so that the epipoles of the 2 images are at infinity.
00010 //  This transformation is called a rectification of the images.
00011 //  It is used in dense matching.
00012 //  The code, here, has been ported from Richard Hartley's code in Target Junior.
00013 //  It also now transforms lines.
00014 //  The method 'factor_Q_matrix_SR' should be removed from here and put in a more
00015 //  suitable place (for example, a class which would handle the fundamental matrix).
00016 //
00017 // \author
00018 //   L. Guichard
00019 // \date 17-MAY-2001
00020 //--------------------------------------------------------------------------------
00021 
00022 
00023 #include <vcl_vector.h>
00024 
00025 #include <vmal/vmal_multi_view_data_vertex_sptr.h>
00026 #include <vmal/vmal_multi_view_data_edge_sptr.h>
00027 #include <vil/vil_image_view.h>
00028 
00029 #include <mvl/TriTensor.h>
00030 
00031 class vmal_rectifier
00032 {
00033  public:
00034 
00035 //---------------------------------------------------------------------------
00036 //: Default constructor.
00037 //---------------------------------------------------------------------------
00038   vmal_rectifier();
00039 
00040 //---------------------------------------------------------------------------
00041 //: Constructor.
00042 //---------------------------------------------------------------------------
00043   vmal_rectifier(vmal_multi_view_data_vertex_sptr mvd_vertex,
00044                  vmal_multi_view_data_edge_sptr mvd_edge,
00045                  int ima_height, int ima_width);
00046 
00047   vmal_rectifier(vcl_vector< vnl_vector<double> >* pts0,
00048                  vcl_vector< vnl_vector<double> >* pts1,
00049                  int ima_height, int ima_width);                 
00050 
00051   ~vmal_rectifier();
00052 
00053   void rectification_matrix(vnl_double_3x3& H0,
00054                             vnl_double_3x3& H1);
00055 
00056   void set_tritensor(TriTensor &tri);
00057 
00058   void compute_joint_epipolar_transform_new (
00059     vnl_double_3* points0,  // Points in one view
00060     vnl_double_3* points1,  // Points in the other view
00061     int numpoints,          // Number of matched points
00062     vnl_double_3x3 &H0, vnl_double_3x3 &H1,  // The matrices to be returned
00063     int in_height, int in_width, //Dimensions of the input image
00064     int &out_height, int &out_width,
00065     double sweeti, double sweetj,// Sweet spot in the first image
00066     bool affine /* = false */);
00067 
00068   void compute_initial_joint_epipolar_transforms (
00069     vnl_double_3* points0,  // Points in one view
00070     vnl_double_3* points1,  // Points in the other view
00071     int numpoints,          // Number of matched points
00072     vnl_double_3x3 &H0, vnl_double_3x3 &H1,  // The matrices to be returned
00073     double sweeti, double sweetj,// Sweet spot in the first image
00074     bool affine /* = false */);
00075 
00076   int compute_initial_joint_epipolar_transforms (
00077     const vnl_double_3x3 &Q,
00078     double ci, double cj,   // Position of reference point in first image
00079     vnl_double_3x3 &H0,     // The first transformation matrix computed
00080     vnl_double_3x3 &H1);    // second transformation matrix to be computed
00081 
00082   vnl_double_3x3 matching_transform (
00083     const vnl_double_3x3 &Q,
00084     const vnl_double_3x3 &H1);
00085 
00086   void factor_Q_matrix_SR (
00087     const vnl_double_3x3 &Q,// 3 x 3 matrix
00088     vnl_double_3x3 &R,      // non-singular matrix
00089     vnl_double_3x3 &S);     // Skew-symmetric part
00090 
00091   vnl_double_3x3 affine_correction (
00092     vnl_double_3* points0,
00093     vnl_double_3* points1,
00094     int numpoints,
00095     const vnl_double_3x3 &H0,
00096     const vnl_double_3x3 &H1);
00097 
00098   void apply_affine_correction (
00099     vnl_double_3* points0,  // Points in one view
00100     vnl_double_3* points1,  // Points in the other view
00101     int numpoints,          // Number of matched points
00102     vnl_double_3x3 &H0, vnl_double_3x3 &H1); // The matrices to be returned
00103 
00104   void rectify_rotate90 (
00105     int &height, int &width,
00106     vnl_double_3x3 &H0,
00107     vnl_double_3x3 &H1);
00108 
00109   void conditional_rectify_rotate180 (
00110     vnl_double_3x3 &H0,
00111     vnl_double_3x3 &H1);
00112 
00113   void resample (vnl_double_3x3 H0, vnl_double_3x3 H1,
00114                  vil_image_view<vxl_byte> imgL,
00115                  vil_image_view<vxl_byte> imgR);
00116   
00117   vil_image_view<vxl_byte>* GetRectifiedImageLeft() {return rectL;}
00118   vil_image_view<vxl_byte>* GetRectifiedImageRight() {return rectR;}
00119 
00120  private:
00121   vnl_double_3* lines0_p_;
00122   vnl_double_3* lines0_q_;
00123   vnl_double_3* lines1_p_;
00124   vnl_double_3* lines1_q_;
00125 
00126   vnl_double_3* points0_;
00127   vnl_double_3* points1_;
00128   int numpoints_;
00129 
00130   int height_;
00131   int width_;
00132   TriTensor tritensor_;
00133   vnl_double_3x3 F12_;
00134   vcl_vector<vnl_double_3> epipoles_;
00135   bool is_f_compute_;
00136   vnl_double_3x3 H0_,H1_;
00137 
00138   vil_image_view<vxl_byte>* rectL;
00139   vil_image_view<vxl_byte>* rectR;
00140 
00141 };
00142 
00143 #endif // vmal_rectifier_h_