bazar  1.3.1
homography.h
Go to the documentation of this file.
1 /*
2 Copyright 2005, 2006 Computer Vision Lab,
3 Ecole Polytechnique Federale de Lausanne (EPFL), Switzerland.
4 All rights reserved.
5 
6 This file is part of BazAR.
7 
8 BazAR is free software; you can redistribute it and/or modify it under the
9 terms of the GNU General Public License as published by the Free Software
10 Foundation; either version 2 of the License, or (at your option) any later
11 version.
12 
13 BazAR is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
15 PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License along with
18 BazAR; if not, write to the Free Software Foundation, Inc., 51 Franklin
19 Street, Fifth Floor, Boston, MA 02110-1301, USA
20 */
21 #ifndef HOMOGRAPHY_H
22 #define HOMOGRAPHY_H
23 
24 #include <iostream>
25 using namespace std;
26 
27 #include <cv.h>
28 
29 
55 class homography : public CvMat
56 {
57 public:
58  homography();
59 
60  homography(float u1, float v1, float up1, float vp1,
61  float u2, float v2, float up2, float vp2,
62  float u3, float v3, float up3, float vp3,
63  float u4, float v4, float up4, float vp4);
64 
65  ~homography();
66 
68  bool estimate(float u1, float v1, float up1, float vp1,
69  float u2, float v2, float up2, float vp2,
70  float u3, float v3, float up3, float vp3,
71  float u4, float v4, float up4, float vp4);
72 
74  void set_match_number(int n);
75  void add_match(float u, float v, float up, float vp);
76  void release_matches(void);
77 
78  void estimate(void);
79 
80  // Display:
81  friend ostream& operator<< (ostream& o, const homography& H);
82 
84  void transform_point(float u, float v, float * up, float * vp);
85  void transform_point(double u, double v, double * up, double * vp);
86 
87  float cvmGet(const int i, const int j);
88  void cvmSet(const int i, const int j, const float val);
89  void cvmSet(const int i, const int j, const double val);
90 
91  friend float cvmGet(const homography * H, const int i, const int j);
92  friend void cvmSet(const homography * H, const int i, const int j, const float val);
93  friend void cvmSet(const homography * H, const int i, const int j, const double val);
94 
95 private:
96  void initialize(void);
97 
98  void add_match(CvMat * AA, CvMat * B, int point_index,
99  float u, float v, float up, float vp);
100 
101  CvMat * AA, * B, * X;
102  CvMat * AA_n, * B_n, * X_n;
103  int match_number, actual_match_number;
104 };
105 
106 ostream& operator<< (ostream& o, const homography& H);
107 
108 inline float homography::cvmGet(const int i, const int j)
109 {
110  return data.fl[3 * i + j];
111 }
112 
113 inline void homography::cvmSet(const int i, const int j, const float val)
114 {
115  data.fl[3 * i + j] = val;
116 }
117 
118 inline void homography::cvmSet(const int i, const int j, const double val)
119 {
120  data.fl[3 * i + j] = (float)val;
121 }
122 
123 inline float cvmGet(const homography * H, const int i, const int j)
124 {
125  assert (H->rows == 3 && H->cols == 3);
126 
127  return H->data.fl[3 * i + j];
128 }
129 
130 inline void cvmSet(const homography * H, const int i, const int j, const float val)
131 {
132  assert (H->rows == 3 && H->cols == 3);
133 
134  H->data.fl[3 * i + j] = val;
135 }
136 
137 inline void cvmSet(const homography * H, const int i, const int j, const double val)
138 {
139  assert (H->rows == 3 && H->cols == 3);
140 
141  H->data.fl[3 * i + j] = (float)val;
142 }
143 
144 #endif // HOMOGRAPHY_H