GSoC2011SfM
0.1
Google Summer of Code 2011: Structure from motion
|
00001 #ifndef _GSOC_SFM_FIELD_OF_VIEW_H 00002 #define _GSOC_SFM_FIELD_OF_VIEW_H 1 00003 #include <vector> 00004 #include <string> 00005 00006 #include "opencv2/core/core.hpp" 00007 00008 #include "macro.h" //SFM_EXPORTS 00009 //#include "Camera.h" 00010 //#include "TracksOfPoints.h" 00011 00012 00013 namespace OpencvSfM{ 00014 00015 class SFM_EXPORTS Camera; 00016 class SFM_EXPORTS TrackOfPoints; 00017 00018 enum paramsToEstimate 00019 { 00020 ROTATION_OK=1, 00021 TRANSLATION_OK=2 00022 }; 00023 00044 class SFM_EXPORTS PointOfView 00045 { 00046 protected: 00047 cv::Mat rotation_; 00048 cv::Mat translation_; 00049 cv::Mat projection_matrix_; 00050 cv::Ptr<Camera> device_; 00051 00052 unsigned char config_; 00053 00054 public: 00063 PointOfView( cv::Ptr<Camera> device,cv::Mat rotation=cv::Mat::eye( 3, 3, CV_64F ),cv::Vec3d translation=cv::Vec3d( 0.0,0.0,0.0 )); 00070 PointOfView( cv::Mat projection_matrix ); 00074 PointOfView( const PointOfView& ref ); 00078 virtual ~PointOfView( void ); 00079 00084 cv::Ptr<Camera> getIntraParameters( ) const{return device_;}; 00085 00090 uchar getNbMissingParams( ) const; 00091 00097 virtual std::vector<cv::Vec2d> project3DPointsIntoImage( std::vector<TrackOfPoints> points ) const; 00103 virtual std::vector<cv::Vec2d> project3DPointsIntoImage( std::vector<cv::Vec3d> points ) const; 00109 virtual cv::Vec2d project3DPointIntoImage( cv::Vec3d point ) const; 00115 virtual bool pointInFrontOfCamera( cv::Vec4d point ) const; 00120 virtual cv::Mat getProjectionMatrix( ) const; 00121 00126 inline cv::Mat getRotationMatrix( ) const 00127 { 00128 return rotation_; 00129 }; 00134 virtual void setRotationMatrix( cv::Mat newRot ) 00135 { 00136 for( int i=0; i<3; ++i ) 00137 for( int j=0; j<3; ++j ) 00138 rotation_.at<double>( i,j ) = newRot.at<double>( i,j ); 00139 }; 00140 00145 inline cv::Mat getTranslationVector( ) const 00146 { 00147 return translation_; 00148 }; 00153 inline void setTranslationVector( cv::Mat newVect ) 00154 { 00155 for( int i=0; i<3; ++i ) 00156 translation_.at<double>( i,0 ) = newVect.at<double>( i,0 ); 00157 }; 00158 00163 inline void rotationAroundX( double angle ) { 00164 double c = cos( angle ), s = sin( angle ); 00165 double data[ ] = {1, 0, 0, 0, c, -s, 0, s, c}; 00166 cv::Mat R( 3,3,CV_64F,data ); 00167 rotation_ *= R; 00168 } 00173 inline void rotationAroundY( double angle ) { 00174 double c = cos( angle ), s = sin( angle ); 00175 double data[ ] = {c, 0, s, 0, 1, 0, -s, 0, c}; 00176 cv::Mat R( 3,3,CV_64F,data ); 00177 rotation_ *= R; 00178 } 00183 inline void rotationAroundZ( double angle ) { 00184 double c = cos( angle ), s = sin( angle ); 00185 double data[ ] = {c, -s, 0, s, c, 0, 0, 0, 1}; 00186 cv::Mat R( 3,3,CV_64F,data ); 00187 rotation_ *= R; 00188 } 00189 00194 static cv::Ptr<PointOfView> read( const cv::FileNode& node ); 00195 00201 static void write( cv::FileStorage& fs, const PointOfView& points ); 00202 00206 void print( std::ostream &flux ) const; 00207 }; 00208 00209 } 00210 SFM_EXPORTS std::ostream& operator<<( std::ostream &flux, OpencvSfM::PointOfView const & pov ); 00211 00212 #endif