00001 #ifndef TRV_HOMOGRAPHYOLD_HPP
00002 #define TRV_HOMOGRAPHYOLD_HPP
00003
00004 #include "kernel/jafarException.hpp"
00005 #include "jmath/jblas.hpp"
00006 #include "jmath/ublasExtra.hpp"
00007 #include "traversability/trv_rotations.hpp"
00008 #include "traversability/trv_util.hpp"
00009
00010
00011 #include "../libsLourakis/homest-1.2/homest.h"
00012
00013 #include <image/Image.hpp>
00014
00015
00016 namespace jafar {
00017 namespace traversability {
00018
00019 class HomographyOld {
00020
00021 private:
00022 CameraPoseParameters mPoseC0;
00023 CameraPoseParameters mPoseC1;
00024 CameraIntrinsicParameters mInternals;
00025 PlaneParameters mPlane;
00026 ImageInfo mImageInfo;
00027
00028 CameraDeltaParameters mDeltaPoseC0C1;
00029 CameraDeltaParameters mDeltaPoseC0Cn;
00030 jblas::mat33 mH_C0C1_geom;
00031 jblas::mat33 mH_C0C1_fine;
00032 jblas::mat33 mH_C0Cn_geom;
00033 jblas::mat33 mH_C0Cn_fine;
00034
00035 jblas::mat33 mDEBUG;
00036
00037 jafar::image::Image mImg0;
00038 jafar::image::Image mImg1;
00039 jafar::image::Image mCFoVMask;
00040
00041
00042 MatchesContainer* mMatches;
00043
00044
00045 jblas::vec mProjError;
00046 double mMeanProjError;
00047 double mStdProjError;
00048
00049
00050
00051
00052
00053 public:
00054 HomographyOld ( void );
00055 ~HomographyOld ( void );
00056
00057 void setImageInfo ( const ImageInfo &imageInfo );
00058 void setPlane ( const PlaneParameters &plane );
00059 void setInternals ( const CameraIntrinsicParameters &internals );
00060 void setPoseCam0 ( const CameraPoseParameters &camPose0 );
00061 void setPoseCam1 ( const CameraPoseParameters &camPose1 );
00062 void setImageCam0 ( jafar::image::Image &img0 );
00063 void setImageCam1 ( jafar::image::Image &img1 );
00064 void setDeltaPose ( void );
00065 void setDeltaPose ( const CameraPoseParameters &camPose0,
00066 const CameraPoseParameters &camPose1 );
00067 void setH_C0Cn_geom ( void );
00068 void setH_C0Cn_fine ( void );
00069 void setH_CnC0_DEBUG ( void );
00070
00071 void setMatches ( MatchesContainer* matches ) { mMatches = matches; }
00072 MatchesContainer* getMatches ( void ) { return mMatches; }
00073
00074 void getPoseCam0 ( CameraPoseParameters &camPose0 );
00075 void getPoseCam1 ( CameraPoseParameters &camPose1 );
00076 void getDeltaPose ( CameraDeltaParameters &delPars );
00077 void getImageCam0 ( jafar::image::Image &img0 );
00078 void getImageCam1 ( jafar::image::Image &img1 );
00079
00080 jblas::mat33 getH_C0C1_geom ( void );
00081 jblas::mat33 getH_C0C1_fine ( void );
00082 jblas::mat33 getH_C0Cn_geom ( void );
00083 jblas::mat33 getH_C0Cn_fine ( void );
00084
00085 jblas::mat33 getH_C1C0_geom ( void );
00086 jblas::mat33 getH_C1C0_fine ( void );
00087 jblas::mat33 getH_CnC0_geom ( void );
00088 jblas::mat33 getH_CnC0_fine ( void );
00089
00090 double getMeanProjError ( void ) { return mMeanProjError; }
00091 double getStdProjError ( void ) { return mStdProjError; }
00092
00093 CameraPoseParameters getPoseCam0 ( void );
00094 CameraPoseParameters getPoseCam1 ( void );
00095 CameraDeltaParameters getDeltaPose ( void );
00096 jafar::image::Image getImageCam0 ( void );
00097 jafar::image::Image getImageCam1 ( void );
00098
00099 void printGeometricInfo ( void );
00100
00101 void initMask ( void );
00102 void initMosaic ( int mosaicWidth, int mosaicHeight, int startU = 0, int startV = 0 );
00103 void calcHomographyGeom ( void );
00104 void calcHomographyGeom ( const CameraPoseParameters &camPose0,
00105 const CameraPoseParameters &camPose1,
00106 const CameraIntrinsicParameters &internals,
00107 const PlaneParameters &plane );
00108 void estimateHomography ( MatchesContainer* mc );
00109 void estimateHomographyR ( MatchesContainer* mc );
00110 void estimateHomographyWithGeom ( MatchesContainer* mc );
00111
00112
00113
00114
00115
00116
00117
00118 void applyHomography ( jafar::image::Image &imgOut );
00119 void applyHomography ( const jblas::mat33 &H_C0C1,
00120 const jafar::image::Image &imgIn,
00121 jafar::image::Image &imgOut );
00122 void addToTraversabilityMap ( const jblas::mat33 &H_CnC0,
00123 const jafar::image::Image &imgTrvIn, const jafar::image::Image &imgIn,
00124 const jafar::image::Image &maskIn,jafar::image::Image &mosaicCntOut, jafar::image::Image &mosaicTrvOut );
00125 template <typename Type> void applyHomographyO( const jblas::mat33 &H_C0C1,
00126 const jafar::image::Image &imgIn,
00127 jafar::image::Image &imgOut,
00128 jafar::image::Image maskCFoV ) {
00129 int widthIn = imgIn.width();
00130 int heightIn = imgIn.height();
00131 int widthOut = imgOut.width();
00132 int heightOut = imgOut.height();
00133
00134 Type p0_x;
00135 Type p0_y;
00136 Type p0_z;
00137 int x0_u; int x0_v;
00138
00139 Type h01v1;
00140 Type h11v1;
00141 Type h21v1;
00142
00143 Type* h00u = new Type[widthOut];
00144 Type* h10u = new Type[widthOut];
00145 Type* h20u = new Type[widthOut];
00146
00147
00148
00149
00150
00151
00152
00153
00154 for (int j=0;j<heightOut;j++)
00155 {
00156 h01v1 = static_cast<Type>(H_C0C1(0,1))*j+static_cast<Type>(H_C0C1(0,2));
00157 h11v1 = static_cast<Type>(H_C0C1(1,1))*j+static_cast<Type>(H_C0C1(1,2));
00158 h21v1 = static_cast<Type>(H_C0C1(2,1))*j+static_cast<Type>(H_C0C1(2,2));
00159
00160 for (int i=0;i<widthOut;i++)
00161 {
00162 if (j==0)
00163 {
00164 h00u[i] = static_cast<Type>(H_C0C1(0,0))*i;
00165 h10u[i] = static_cast<Type>(H_C0C1(1,0))*i;
00166 h20u[i] = static_cast<Type>(H_C0C1(2,0))*i;
00167 }
00168
00169 p0_x = h00u[i]+h01v1;
00170 p0_y = h10u[i]+h11v1;
00171 p0_z = h20u[i]+h21v1;
00172
00173 x0_u = round((p0_x/p0_z));
00174 x0_v = round((p0_y/p0_z));
00175
00176 if (x0_u >= 0 and x0_v >= 0 and x0_u < widthIn and x0_v < heightIn)
00177 {
00178 imgOut.setPixelValue<uint8_t>(imgIn.getPixelValue<uint8_t>(x0_u,x0_v),i,j);
00179 if (maskCFoV)
00180 {
00181 maskCFoV.setPixelValue<uint8_t>(255,i,j);
00182 }
00183
00184
00185 }
00186 else
00187 {
00188
00189
00190 imgOut.setPixelValue<uint8_t>(0,i,j);
00191 }
00192 }
00193 }
00194
00195 delete [] h00u;
00196 delete [] h10u;
00197 delete [] h20u;
00198 }
00199 void addToMosaic ( const jblas::mat33 &H_CnC0,
00200 const jafar::image::Image &imgIn,
00201 jafar::image::Image &mosaicOut );
00202 void addCornersToMosaic ( const jblas::mat33 &H_C0Cn,
00203 const jafar::image::Image &imgIn,
00204 jafar::image::Image &mosaicOut );
00205
00206 void calcHomographyDecomposition ( const jblas::mat33 &H_C1C0, const jblas::mat33 K,
00207 jblas::mat33 &R_C1C0, jblas::vec3 &t_C1, jblas::vec3 &n_C0 );
00208
00209
00210 void calcProjErrorStatsOld ( const jblas::mat33 &H_C0C1, const jafar::gfm::MatchingResult &rm );
00211 void calcProjErrorStats ( const jblas::mat33 &H_C0C1, const MatchesContainer &mc );
00212
00213 private:
00214 void calcA_i ( const double x0u, const double x0v, const double x1u, const double x1v, jblas::mat &A_i, const double weight = 1.0 );
00215
00216 void calcJ_i( const fdetect::InterestFeature* x0, const fdetect::InterestFeature* x1, jblas::mat &J_i );
00217 void updatePlaneParameters ( void );
00218 void calcBoundingRect ( const jblas::mat33 &H_COutCIn,
00219 const jafar::image::Image &imgIn, cv::Rect &boundingRect );
00220 void shrinkBoundingRectToImage ( const jafar::image::Image &img, cv::Rect &boundingRect );
00221
00222
00223
00224
00225
00226
00227
00228
00229 };
00230
00231
00232 }
00233 }
00234
00235 #endif
00236