MRPT  1.9.9
xform.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #ifndef XFORM_H
11 #define XFORM_H
12 
13 //#include "cxcore.h"
14 // Universal include for all versions of OpenCV
15 #include <mrpt/otherlibs/do_opencv_includes.h>
16 
17 /********************************** Structures *******************************/
18 
19 struct feature;
20 
21 /** holds feature data relevant to ransac */
23 {
25  int sampled;
26 };
27 
28 /******************************* Defs and macros *****************************/
29 
30 /* RANSAC error tolerance in pixels */
31 #define RANSAC_ERR_TOL 3
32 
33 /** pessimistic estimate of fraction of inlers for RANSAC */
34 #define RANSAC_INLIER_FRAC_EST 0.25
35 
36 /** estimate of the probability that a correspondence supports a bad model */
37 #define RANSAC_PROB_BAD_SUPP 0.10
38 
39 /* extracts a feature's RANSAC data */
40 #define feat_ransac_data(feat) ((struct ransac_data*)(feat)->feature_data)
41 
42 /**
43 Prototype for transformation functions passed to ransac_xform(). Functions
44 of this type should compute a transformation matrix given a set of point
45 correspondences.
46 
47 @param pts array of points
48 @param mpts array of corresponding points; each \a pts[\a i], \a i=0..\a n-1,
49  corresponds to \a mpts[\a i]
50 @param n number of points in both \a pts and \a mpts
51 
52 @return Should return a transformation matrix that transforms each point in
53  \a pts to the corresponding point in \a mpts or nullptr on failure.
54 */
55 typedef CvMat* (*ransac_xform_fn)(CvPoint2D64f* pts, CvPoint2D64f* mpts, int n);
56 
57 /**
58 Prototype for error functions passed to ransac_xform(). For a given
59 point, its correspondence, and a transform, functions of this type should
60 compute a measure of error between the correspondence and the point after
61 the point has been transformed by the transform.
62 
63 @param pt a point
64 @param mpt \a pt's correspondence
65 @param T a transform
66 
67 @return Should return a measure of error between \a mpt and \a pt after
68  \a pt has been transformed by the transform \a T.
69 */
70 typedef double (*ransac_err_fn)(CvPoint2D64f pt, CvPoint2D64f mpt, CvMat* M);
71 
72 /***************************** Function Prototypes ***************************/
73 
74 /**
75 Calculates a best-fit image transform from image feature correspondences
76 using RANSAC.
77 
78 For more information refer to:
79 
80 Fischler, M. A. and Bolles, R. C. Random sample consensus: a paradigm for
81 model fitting with applications to image analysis and automated cartography.
82 <EM>Communications of the ACM, 24</EM>, 6 (1981), pp. 381--395.
83 
84 @param features an array of features; only features with a non-NULL match
85  of type \a mtype are used in homography computation
86 @param n number of features in \a feat
87 @param mtype determines which of each feature's match fields to use
88  for transform computation; should be one of FEATURE_FWD_MATCH,
89  FEATURE_BCK_MATCH, or FEATURE_MDL_MATCH; if this is FEATURE_MDL_MATCH,
90  correspondences are assumed to be between a feature's img_pt field
91  and its match's mdl_pt field, otherwise correspondences are assumed to
92  be between the the feature's img_pt field and its match's img_pt field
93 @param xform_fn pointer to the function used to compute the desired
94  transformation from feature correspondences
95 @param m minimum number of correspondences necessary to instantiate the
96  transform computed by \a xform_fn
97 @param p_badxform desired probability that the final transformation
98  returned by RANSAC is corrupted by outliers (i.e. the probability that
99  no samples of all inliers were drawn)
100 @param err_fn pointer to the function used to compute a measure of error
101  between putative correspondences for a given transform
102 @param err_tol correspondences within this distance of each other are
103  considered as inliers for a given transform
104 @param inliers if not nullptr, output as an array of pointers to the final
105  set of inliers
106 @param n_in if not nullptr, output as the final number of inliers
107 
108 @return Returns a transformation matrix computed using RANSAC or NULL
109  on error or if an acceptable transform could not be computed.
110 */
111 extern CvMat* ransac_xform(
112  struct feature* features, int n, int mtype, ransac_xform_fn xform_fn, int m,
113  double p_badxform, ransac_err_fn err_fn, double err_tol,
114  struct feature*** inliers, int* n_in);
115 
116 /**
117 Calculates a least-squares planar homography from point correspondeces.
118 Intended for use as a ransac_xform_fn.
119 
120 @param pts array of points
121 @param mpts array of corresponding points; each \a pts[\a i], \a i=0..\a n-1,
122  corresponds to \a mpts[\a i]
123 @param n number of points in both \a pts and \a mpts; must be at least 4
124 
125 @return Returns the \f$3 \times 3\f$ least-squares planar homography
126  matrix that transforms points in \a pts to their corresponding points
127  in \a mpts or nullptr if fewer than 4 correspondences were provided
128 */
129 extern CvMat* lsq_homog(CvPoint2D64f* pts, CvPoint2D64f* mpts, int n);
130 
131 /**
132 Calculates the transfer error between a point and its correspondence for
133 a given homography, i.e. for a point \f$x\f$, it's correspondence \f$x'\f$,
134 and homography \f$H\f$, computes \f$d(x', Hx)^2\f$. Intended for use as a
135 ransac_err_fn.
136 
137 @param pt a point
138 @param mpt \a pt's correspondence
139 @param H a homography matrix
140 
141 @return Returns the transfer error between \a pt and \a mpt given \a H
142 */
143 extern double homog_xfer_err(CvPoint2D64f pt, CvPoint2D64f mpt, CvMat* H);
144 
145 /**
146 Performs a perspective transformation on a single point. That is, for a
147 point \f$(x, y)\f$ and a \f$3 \times 3\f$ matrix \f$T\f$ this function
148 returns the point \f$(u, v)\f$, where<BR>
149 
150 \f$[x' \ y' \ w']^T = T \times [x \ y \ 1]^T\f$,<BR>
151 
152 and<BR>
153 
154 \f$(u, v) = (x'/w', y'/w')\f$.
155 
156 Note that affine transforms are a subset of perspective transforms.
157 
158 @param pt a 2D point
159 @param T a perspective transformation matrix
160 
161 @return Returns the point \f$(u, v)\f$ as above.
162 */
163 extern CvPoint2D64f persp_xform_pt(CvPoint2D64f pt, CvMat* T);
164 
165 #endif
double homog_xfer_err(CvPoint2D64f pt, CvPoint2D64f mpt, CvMat *H)
Calculates the transfer error between a point and its correspondence for a given homography...
GLenum GLsizei n
Definition: glext.h:5074
holds feature data relevant to ransac
Definition: xform.h:22
CvPoint2D64f persp_xform_pt(CvPoint2D64f pt, CvMat *T)
Performs a perspective transformation on a single point.
CvMat * lsq_homog(CvPoint2D64f *pts, CvPoint2D64f *mpts, int n)
Calculates a least-squares planar homography from point correspondeces.
Structure to represent an affine invariant image feature.
Definition: imgfeatures.h:49
void * orig_feat_data
Definition: xform.h:24
int sampled
Definition: xform.h:25
CvMat * ransac_xform(struct feature *features, int n, int mtype, ransac_xform_fn xform_fn, int m, double p_badxform, ransac_err_fn err_fn, double err_tol, struct feature ***inliers, int *n_in)
Calculates a best-fit image transform from image feature correspondences using RANSAC.
double(* ransac_err_fn)(CvPoint2D64f pt, CvPoint2D64f mpt, CvMat *M)
Prototype for error functions passed to ransac_xform().
Definition: xform.h:70
CvMat *(* ransac_xform_fn)(CvPoint2D64f *pts, CvPoint2D64f *mpts, int n)
Prototype for transformation functions passed to ransac_xform().
Definition: xform.h:55



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020