homography.h
Go to the documentation of this file.
1 /* Copyright (C) 2013-2016, The Regents of The University of Michigan.
2 All rights reserved.
3 
4 This software was developed in the APRIL Robotics Lab under the
5 direction of Edwin Olson, ebolson@umich.edu. This software may be
6 available under alternative licensing terms; contact the address above.
7 
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions are met:
10 
11 1. Redistributions of source code must retain the above copyright notice, this
12  list of conditions and the following disclaimer.
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 The views and conclusions contained in the software and documentation are those
29 of the authors and should not be interpreted as representing official policies,
30 either expressed or implied, of the Regents of The University of Michigan.
31 */
32 
33 #ifndef _HOMOGRAPHY_H
34 #define _HOMOGRAPHY_H
35 
36 #include "matd.h"
37 #include "zarray.h"
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
129 // correspondences is a list of float[4]s, consisting of the points x
130 // and y concatenated. We will compute a homography such that y = Hx
131 // Specifically, float [] { a, b, c, d } where x = [a b], y = [c d].
132 
133 
134 #define HOMOGRAPHY_COMPUTE_FLAG_INVERSE 1
135 #define HOMOGRAPHY_COMPUTE_FLAG_SVD 0
136 
137 matd_t *homography_compute(zarray_t *correspondences, int flags);
138 
139 //void homography_project(const matd_t *H, double x, double y, double *ox, double *oy);
140 static inline void homography_project(const matd_t *H, double x, double y, double *ox, double *oy)
141 {
142  double xx = MATD_EL(H, 0, 0)*x + MATD_EL(H, 0, 1)*y + MATD_EL(H, 0, 2);
143  double yy = MATD_EL(H, 1, 0)*x + MATD_EL(H, 1, 1)*y + MATD_EL(H, 1, 2);
144  double zz = MATD_EL(H, 2, 0)*x + MATD_EL(H, 2, 1)*y + MATD_EL(H, 2, 2);
145 
146  *ox = xx / zz;
147  *oy = yy / zz;
148 }
149 
150 // assuming that the projection matrix is:
151 // [ fx 0 cx 0 ]
152 // [ 0 fy cy 0 ]
153 // [ 0 0 1 0 ]
154 //
155 // And that the homography is equal to the projection matrix times the model matrix,
156 // recover the model matrix (which is returned). Note that the third column of the model
157 // matrix is missing in the expresison below, reflecting the fact that the homography assumes
158 // all points are at z=0 (i.e., planar) and that the element of z is thus omitted.
159 // (3x1 instead of 4x1).
160 //
161 // [ fx 0 cx 0 ] [ R00 R01 TX ] [ H00 H01 H02 ]
162 // [ 0 fy cy 0 ] [ R10 R11 TY ] = [ H10 H11 H12 ]
163 // [ 0 0 1 0 ] [ R20 R21 TZ ] = [ H20 H21 H22 ]
164 // [ 0 0 1 ]
165 //
166 // fx*R00 + cx*R20 = H00 (note, H only known up to scale; some additional adjustments required; see code.)
167 // fx*R01 + cx*R21 = H01
168 // fx*TX + cx*TZ = H02
169 // fy*R10 + cy*R20 = H10
170 // fy*R11 + cy*R21 = H11
171 // fy*TY + cy*TZ = H12
172 // R20 = H20
173 // R21 = H21
174 // TZ = H22
175 matd_t *homography_to_pose(const matd_t *H, double fx, double fy, double cx, double cy);
176 
177 // Similar to above
178 // Recover the model view matrix assuming that the projection matrix is:
179 //
180 // [ F 0 A 0 ] (see glFrustrum)
181 // [ 0 G B 0 ]
182 // [ 0 0 C D ]
183 // [ 0 0 -1 0 ]
184 
185 matd_t *homography_to_model_view(const matd_t *H, double F, double G, double A, double B, double C, double D);
186 
187 #ifdef __cplusplus
188 }
189 #endif
190 
191 #endif
static void homography_project(const matd_t *H, double x, double y, double *ox, double *oy)
Definition: homography.h:140
#define MATD_EL(m, row, col)
Definition: matd.h:71
Definition: matd.h:51
Definition: zarray.h:49
matd_t * homography_to_pose(const matd_t *H, double fx, double fy, double cx, double cy)
Definition: homography.c:281
matd_t * homography_to_model_view(const matd_t *H, double F, double G, double A, double B, double C, double D)
Definition: homography.c:366
matd_t * homography_compute(zarray_t *correspondences, int flags)
Definition: homography.c:43


apriltags2
Author(s): Danylo Malyuta
autogenerated on Fri Oct 19 2018 04:02:32