Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #include "CvFundamentalMat.h"
00009
00010
00011
00012 #include <math.h>
00013
00014 #define THIS CvFundamentalMat
00015
00016 THIS::THIS ( std::vector< KeyPoint >* keyPoints1, std::vector< KeyPoint >* keyPoints2, std::list< KeyPointMatch >& matches )
00017 {
00018 m_KeyPoints1 = keyPoints1;
00019 m_KeyPoints2 = keyPoints2;
00020 m_Matches = matches;
00021 m_Success = false;
00022 m_MaxReprojectionError = 1;
00023 }
00024
00025 THIS::~THIS()
00026 {
00027 }
00028
00029 bool THIS::computeFundamentalMat()
00030 {
00031 double fundamentalMat[9];
00032
00033 memset ( fundamentalMat, 0, 9*sizeof ( double ) );
00034 m_FundMatCv = cvMat ( 3, 3, CV_64F, fundamentalMat );
00035
00036 std::vector<CvPoint2D32f> points1Cv, points2Cv;
00037
00038
00039 int numMatches = m_Matches.size();
00040
00041 if ( numMatches < 4 )
00042 {
00043 return false;
00044 }
00045
00046
00047 points1Cv.resize ( numMatches );
00048 points2Cv.resize ( numMatches );
00049
00050
00051 std::list<KeyPointMatch>::iterator currentMatch = m_Matches.begin();
00052 int i = 0;
00053 while ( currentMatch != m_Matches.end() )
00054 {
00055 points1Cv[i] = cvPoint2D32f ( ( *m_KeyPoints1 ) [ currentMatch->index1 ].x,
00056 ( *m_KeyPoints1 ) [ currentMatch->index1 ].y );
00057 points2Cv[i] = cvPoint2D32f ( ( *m_KeyPoints2 ) [ currentMatch->index2 ].x,
00058 ( *m_KeyPoints2 ) [ currentMatch->index2 ].y );
00059 currentMatch++;
00060 i++;
00061 }
00062
00063 m_Points1CvMat = cvMat ( 1, numMatches, CV_32FC2, &points1Cv[0] );
00064 m_Points2CvMat = cvMat ( 1, numMatches, CV_32FC2, &points2Cv[0] );
00065
00066 int method = 0;
00067 switch (CV_FM_7POINT)
00068 {
00069 case 0 :
00070 method = CV_FM_7POINT;
00071 break;
00072 case 1 :
00073 method = CV_FM_8POINT;
00074 break;
00075 case 2 :
00076 method = CV_FM_RANSAC;
00077 break;
00078 case 3:
00079 method = CV_FM_LMEDS;
00080 break;
00081 default:
00082
00083 break;
00084 }
00085 CvMat* status;
00086 status = cvCreateMat(1,numMatches,CV_8UC1);
00087
00088
00089
00090
00091 m_Success = cvFindFundamentalMat( &m_Points2CvMat, &m_Points1CvMat, &m_FundMatCv, method, m_MaxReprojectionError,0.99,status);
00092
00093
00094
00095 return m_Success > 0 ? true : false;
00096 }
00097
00098 void THIS::eliminateBadMatches()
00099 {
00100 std::vector<Point2D> points2;
00101 std::vector<Point2D> projPoints;
00102
00103 points2.reserve( m_Matches.size() );
00104
00105 std::list<KeyPointMatch>::iterator currentMatch = m_Matches.begin();
00106 while ( currentMatch != m_Matches.end() )
00107 {
00108 Point2D pos2 = ( *m_KeyPoints2 ) [ currentMatch->index2 ].position();
00109 points2.push_back( pos2 );
00110 currentMatch++;
00111 }
00112
00113
00114
00115
00116
00117 double correspondent_lines[3];
00118
00119 memset ( correspondent_lines, 0, 3*sizeof ( double ) );
00120
00121 CvMat correspondent_linesCV;
00122 correspondent_linesCV= cvMat(3,m_Matches.size(),CV_32F,correspondent_lines);
00123
00124 cvComputeCorrespondEpilines(&m_Points2CvMat, 1, &m_FundMatCv, &correspondent_linesCV);
00125
00126
00127
00128 currentMatch = m_Matches.begin();
00129 int i = 0;
00130 while ( currentMatch != m_Matches.end() )
00131 {
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145 i++;
00146 }
00147 }
00148
00149
00150 #undef THIS