Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleHMatrixEstimation.cpp
1 /* This file is part of the BIAS library (Basic ImageAlgorithmS).
2 
3  Copyright (C) 2003-2009 (see file CONTACT for details)
4  Multimediale Systeme der Informationsverarbeitung
5  Institut fuer Informatik
6  Christian-Albrechts-Universitaet Kiel
7 
8  BIAS is free software; you can redistribute it and/or modify
9  it under the terms of the GNU Lesser General Public License as published by
10  the Free Software Foundation; either version 2.1 of the License, or
11  (at your option) any later version.
12 
13  BIAS is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public License
19  along with BIAS; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*/
21 
22 
23 /**
24  @example ExampleHMatrixEstimation.cpp
25  @relates HMatrixExtimation
26  @brief Example computing H matrix
27  @ingroup g_examples
28  @author woelk 05/2008 www.vision-n.de
29 */
30 
31 #include <Geometry/HMatrixEstimation.hh>
32 #include <vector>
33 
34 using namespace BIAS;
35 using namespace std;
36 
37 
38 int main(int argc, char *argv[])
39 {
40  HMatrixEstimation Hest;
41  const int num_points=4;
42  vector<HomgPoint2D> frompoints(4), topoints(4);
43  const int num_fields = 22;
44  frompoints[0].Set(0.0, 0.0, 1.0);
45  frompoints[1].Set((double)(num_fields), 0.0, 1.0);
46  frompoints[2].Set((double)(num_fields), (double)(num_fields), 1.0);
47  frompoints[3].Set(0.0, (double)(num_fields), 1.0);
48  topoints[0].Set(521.8942308, 64.35576923, 1.);
49  topoints[1].Set(527., 280., 1.);
50  topoints[2].Set(310.96, 282.0, 1.);
51  topoints[3].Set(309., 62., 1.);
52 
53  HMatrix H;
54  int res = Hest.Compute(frompoints, topoints, H);
55  if (res!=0) {
56  BIASERR("error computing H: "<<res);
57  return res;
58  } else {
59  HomgPoint2D hfrom;
60  for (int i=0; i<num_points; i++){
61  hfrom = H * frompoints[i];
62  BIASASSERT(!hfrom.IsAtInfinity());
63  hfrom.Homogenize();
64  cout << " from = "<<frompoints[i]
65  << "\nH * from = "<<hfrom
66  << "\n to = "<<topoints[i]<<"\n--------\n";
67  }
68 
69  }
70  return 0;
71 }
class HomgPoint2D describes a point with 2 degrees of freedom in projective coordinates.
Definition: HomgPoint2D.hh:67
a 3x3 Matrix describing projective transformations between planes
Definition: HMatrix.hh:39
HomgPoint2D & Homogenize()
homogenize class data member elements to W==1 by divison by W
Definition: HomgPoint2D.hh:215
bool IsAtInfinity() const
Definition: HomgPoint2D.hh:165
int Compute(const std::vector< BIAS::HomgPoint2D > &fromPoints, const std::vector< BIAS::HomgPoint2D > &toPoints, HMatrix &H)
Calculate homography between 2d points using the DLT.
Estimate 3x3 matrix relating image coordinates with each other, i.e.