Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Example7Point.cpp
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 /**
26  @example Example7Point.cpp
27  @relates FMatrixEstimation
28  @brief Example for 7 point pose estimator
29  @ingroup g_examples
30  @author MIP
31 */
32 
33 #include <Geometry/FMatrixEstimation.hh>
34 #include <MathAlgo/SVD.hh>
35 
36 using namespace BIAS;
37 using namespace std;
38 
39 typedef vector<HomgPoint2D> PointVector;
40 
41 void
42 loadFlowVectors(char* filename, PointVector& match1,
43  PointVector& match2)
44 {
45  match1.clear();
46  match2.clear();
47  FILE *stream;
48  stream = fopen ( filename , "rb" );
49  char *buffer = new char[256];
50  float x1, y1, w1, x2, y2, w2;
51  bool done=false;
52  while (!done)
53  {
54  char *r = fgets(buffer, 256, stream);
55  if (r == NULL) exit(-1); //error reading from file
56  if (buffer[0] == '#' || buffer[0] == '\n') continue; //commentary
57  if (feof(stream)) {
58  done=true;
59  break;
60  }
61  sscanf(buffer, "%f %f %f %f %f %f \n", &x1, &y1, &w1, &x2, &y2, &w2);
62  match1.push_back(HomgPoint2D(x1, y1, w1));
63  match2.push_back(HomgPoint2D(x2, y2, w2));
64  }
65  fclose(stream);
66 }
67 
68 int main(int argc, char *argv[])
69 {
70  vector<HomgPoint2D> p1, p2;
71 
72  if (argc>=2){
73  loadFlowVectors(argv[1], p1, p2);
74  for (int i=0; i<(int)p1.size(); i++){
75  cout << p1[i]<<"\t"<<p2[i]<<endl;
76  }
77  } else {
78  cerr << argv[0]<<" pointfile\n";
79  return -1;
80  }
81 
82  vector<FMatrix> Fvec;
83  FMatrixEstimation fest;
84 
85  if (fest.SevenPoint(Fvec, p1, p2)!=0){
86  BIASERR("error estimating F");
87  }
88 
89  SVD svd;
90  for (int i=0; i<(int)Fvec.size(); i++){
91  svd.Compute((Matrix<double>)Fvec[i]);
92  cout << "singular values of "<<i<<"th solution are "
93  <<svd.GetS()[0]<<"\t"<<svd.GetS()[1]<<"\t"<<svd.GetS()[2]<<endl;
94  }
95 
96  return 0;
97 }
computes and holds the singular value decomposition of a rectangular (not necessarily quadratic) Matr...
Definition: SVD.hh:92
int Compute(const Matrix< double > &M, double ZeroThreshold=DEFAULT_DOUBLE_ZERO_THRESHOLD)
set a new matrix and compute its decomposition.
Definition: SVD.cpp:102
functions for estimating a fundamental matrix (FMatrix) given a set of 2d-2d correspondences (no outl...
const Vector< double > & GetS() const
return S which is a vector of the singular values of A in descending order.
Definition: SVD.hh:167
int SevenPoint(std::vector< BIAS::FMatrix > &Fvec, const std::vector< BIAS::HomgPoint2D > &p1, const std::vector< BIAS::HomgPoint2D > &p2)
compute a vector of FMatrices from seven point correspondences
class BIASGeometryBase_EXPORT HomgPoint2D