19 #include <visp/vpHomography.h>
20 #include <visp/vpColVector.h>
21 #include <visp/vpRansac.h>
32 iscolinear(
double *x1,
double *x2,
double *x3)
49 double threshold_area)
54 for (i=1 ; i < 4 ; i++)
56 if (ind[i]==ind[j])
return true ;
58 unsigned int n = x.
getRows()/4 ;
64 for(i = 0 ; i < 4 ; i++)
66 pb[i][0] = x[2*ind[i]] ;
67 pb[i][1] = x[2*ind[i]+1] ;
70 pa[i][0] = x[2*n+2*ind[i]] ;
71 pa[i][1] = x[2*n+2*ind[i]+1] ;
77 double area012 = (-pa[j][0]*pa[i][1] + pa[k][0]*pa[i][1] +
78 pa[i][0]*pa[j][1] - pa[k][0]*pa[j][1] +
79 -pa[i][0]*pa[k][1] + pa[1][j]*pa[k][1]);
82 double area013 = (-pa[j][0]*pa[i][1] + pa[k][0]*pa[i][1] +
83 pa[i][0]*pa[j][1] - pa[k][0]*pa[j][1] +
84 -pa[i][0]*pa[k][1] + pa[1][j]*pa[k][1]);
87 double area023 = (-pa[j][0]*pa[i][1] + pa[k][0]*pa[i][1] +
88 pa[i][0]*pa[j][1] - pa[k][0]*pa[j][1] +
89 -pa[i][0]*pa[k][1] + pa[1][j]*pa[k][1]);
92 double area123 = (-pa[j][0]*pa[i][1] + pa[k][0]*pa[i][1] +
93 pa[i][0]*pa[j][1] - pa[k][0]*pa[j][1] +
94 -pa[i][0]*pa[k][1] + pa[1][j]*pa[k][1]);
96 double sum_area = area012 + area013 + area023 + area123;
98 return ((sum_area < threshold_area) ||
99 (iscolinear(pa[0],pa[1],pa[2]) ||
100 iscolinear(pa[0],pa[1],pa[3]) ||
101 iscolinear(pa[0],pa[2],pa[3]) ||
102 iscolinear(pa[1],pa[2],pa[3]) ||
103 iscolinear(pb[0],pb[1],pb[2]) ||
104 iscolinear(pb[0],pb[1],pb[3]) ||
105 iscolinear(pb[0],pb[2],pb[3]) ||
106 iscolinear(pb[1],pb[2],pb[3])));
123 for (
unsigned int i = 1; i < 4 ; i++)
124 for (
unsigned int j = 0 ;j < i ; j++)
125 if (ind[i] == ind[j])
return true ;
127 unsigned int n = x.
getRows()/4;
130 unsigned int n2 = 2 * n;
132 for(
unsigned int i = 0; i < 4 ;i++)
136 pb[i][1] = x[ind2+1];
139 pa[i][0] = x[n2+ind2] ;
140 pa[i][1] = x[n2+ind2+1] ;
143 return ( iscolinear(pa[0],pa[1],pa[2]) ||
144 iscolinear(pa[0],pa[1],pa[3]) ||
145 iscolinear(pa[0],pa[2],pa[3]) ||
146 iscolinear(pa[1],pa[2],pa[3]) ||
147 iscolinear(pb[0],pb[1],pb[2]) ||
148 iscolinear(pb[0],pb[1],pb[3]) ||
149 iscolinear(pb[0],pb[2],pb[3]) ||
150 iscolinear(pb[1],pb[2],pb[3]));
157 unsigned int n = x.
getRows()/4 ;
160 unsigned int n2 = n * 2;
162 for(i=0 ; i < 4 ; i++)
169 ya[i] = x[n2+ind2+1] ;
183 for (i=0 ; i <9 ; i++)
196 unsigned int n = x.
getRows()/4 ;
197 unsigned int n2 = n * 2;
205 for( i=0 ; i < n ; i++)
214 pa[i][0] = x[n2+i2] ;
215 pa[i][1] = x[n2+i2+1] ;
221 for (i=0 ; i <9 ; i++)
231 for (i=0 ; i <n ; i++)
235 d[i] = sqrt((pa[i] - Hpb ).
sumSquare()) ;
246 vpHomography::initRansac(
unsigned int n,
247 double *xb,
double *yb,
248 double *xa,
double *ya,
252 unsigned int n2 = n * 2;
254 for (
unsigned int i=0 ; i < n ; i++)
266 double *xb,
double *yb,
267 double *xa,
double *ya ,
274 vpHomography::initRansac(n, xb, yb, xa, ya, x) ;
284 for (
unsigned int i = 0 ;i < 9 ;i++)
324 double *xb,
double *yb,
325 double *xa,
double *ya ,
331 double areaThreshold)
334 vpHomography::initRansac(n, xb, yb, xa, ya, x);
343 for (
unsigned int i = 0 ;i < 9 ;i++)
Definition of the vpMatrix class.
static vpColVector cross(const vpColVector &a, const vpColVector &b)
double sumSquare() const
return sum of the Aij^2 (for all i, for all j)
static void computeTransformation(vpColVector &x, unsigned int *ind, vpColVector &M)
double * data
address of the first element of the data array
This class aims to compute the homography wrt.two images.
void setIdentity(const double &val=1.0)
static void HLM(unsigned int n, double *xb, double *yb, double *xa, double *ya, bool isplan, vpHomography &aHb)
Computes the homography matrix from planar or non planar points using Ezio Malis linear method (HLM)...
static double computeResidual(vpColVector &x, vpColVector &M, vpColVector &d)
Class that provides a data structure for the column vectors as well as a set of operations on these v...
static bool ransac(unsigned int npts, vpColVector &x, unsigned int s, double t, vpColVector &model, vpColVector &inliers, int consensus=1000, double areaThreshold=0.0, const int maxNbumbersOfTrials=10000)
RANSAC - Robustly fits a model to data with the RANSAC algorithm.
static bool ransac(unsigned int n, double *xb, double *yb, double *xa, double *ya, vpHomography &aHb, int consensus=1000, double threshold=1e-6)
static bool degenerateConfiguration(vpColVector &x, unsigned int *ind)
unsigned int getRows() const
Return the number of rows of the matrix.
void resize(const unsigned int i, const bool flagNullify=true)