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


apriltag
Author(s): Edwin Olson , Max Krogius
autogenerated on Mon Jun 26 2023 02:26:12