66 const int nMatchCandidates = matchCandidates.
GetSize();
68 if (nMatchCandidates < 3)
70 printf(
"error: at least 3 match candidates must be provided for RANSAC::RANSACAffineTransformation (%i provided)\n", nMatchCandidates);
77 for (i = 0; i < nIterations; i++)
80 const int nFirstIndex = rand() % nMatchCandidates;
84 do { nTempIndex = rand() % nMatchCandidates; }
while (nTempIndex == nFirstIndex);
85 const int nSecondIndex = nTempIndex;
87 do { nTempIndex = rand() % nMatchCandidates; }
while (nTempIndex == nFirstIndex || nTempIndex == nSecondIndex);
89 Vec2d pFeaturesLeft[3];
90 Vec2d pFeaturesRight[3];
93 Math2d::SetVec(pFeaturesLeft[1], matchCandidates[nSecondIndex].p1);
96 Math2d::SetVec(pFeaturesRight[0], matchCandidates[nFirstIndex].p2);
97 Math2d::SetVec(pFeaturesRight[1], matchCandidates[nSecondIndex].p2);
106 for (
int j = 0; j < nMatchCandidates; j++)
113 if (distance < fRANSACThreshold)
126 resultMatches.
Clear();
128 for (i = 0; i < nMatchCandidates; i++)
135 if (distance < fRANSACThreshold)
150 const int nMatchCandidates = matchCandidates.
GetSize();
152 if (nMatchCandidates < 4)
154 printf(
"error: at least 4 match candidates must be provided for RANSAC::RANSACHomography (%i provided)\n", nMatchCandidates);
161 for (i = 0; i < nIterations; i++)
164 const int nFirstIndex = rand() % nMatchCandidates;
168 do { nTempIndex = rand() % nMatchCandidates; }
while (nTempIndex == nFirstIndex);
169 const int nSecondIndex = nTempIndex;
171 do { nTempIndex = rand() % nMatchCandidates; }
while (nTempIndex == nFirstIndex || nTempIndex == nSecondIndex);
172 const int nThirdIndex = nTempIndex;
174 do { nTempIndex = rand() % nMatchCandidates; }
while (nTempIndex == nFirstIndex || nTempIndex == nSecondIndex || nTempIndex == nThirdIndex);
176 Vec2d pFeaturesLeft[4];
177 Vec2d pFeaturesRight[4];
179 Math2d::SetVec(pFeaturesLeft[0], matchCandidates[nFirstIndex].p1);
180 Math2d::SetVec(pFeaturesLeft[1], matchCandidates[nSecondIndex].p1);
181 Math2d::SetVec(pFeaturesLeft[2], matchCandidates[nThirdIndex].p1);
184 Math2d::SetVec(pFeaturesRight[0], matchCandidates[nFirstIndex].p2);
185 Math2d::SetVec(pFeaturesRight[1], matchCandidates[nSecondIndex].p2);
186 Math2d::SetVec(pFeaturesRight[2], matchCandidates[nThirdIndex].p2);
187 Math2d::SetVec(pFeaturesRight[3], matchCandidates[nTempIndex].p1);
195 for (
int j = 0; j < nMatchCandidates; j++)
202 if (distance < fRANSACThreshold)
215 resultMatches.
Clear();
217 for (i = 0; i < nMatchCandidates; i++)
224 if (distance < fRANSACThreshold)
239 const int nPointCandidates = pointCandidates.
GetSize();
241 if (nPointCandidates < 3)
243 printf(
"error: at least 3 point candidates must be provided for RANSAC::RANSAC3DPlane (%i provided)\n", nPointCandidates);
249 Vec3d best_n = { 0.0f, 0.0f };
251 for (i = 0; i < nIterations; i++)
254 const int nFirstIndex = rand() % nPointCandidates;
258 do { nTempIndex = rand() % nPointCandidates; }
while (nTempIndex == nFirstIndex);
259 const int nSecondIndex = nTempIndex;
261 do { nTempIndex = rand() % nPointCandidates; }
while (nTempIndex == nFirstIndex || nTempIndex == nSecondIndex);
263 const Vec3d &p1 = pointCandidates[nFirstIndex];
264 const Vec3d &p2 = pointCandidates[nSecondIndex];
265 const Vec3d &p3 = pointCandidates[nTempIndex];
276 for (
int j = 0; j < nPointCandidates; j++)
290 resultPoints.
Clear();
292 for (i = 0; i < nPointCandidates; i++)
void ApplyHomography(const Mat3d &A, const Vec2d &p, Vec2d &result)
bool DetermineHomography(const Vec2d *pSourcePoints, const Vec2d *pTargetPoints, int nPoints, Mat3d &A, bool bUseSVD=false)
Determines a homography based on a set of 2d-2d point correspondences.
void CrossProduct(const Vec3d &vector1, const Vec3d &vector2, Vec3d &result)
float ScalarProduct(const Vec3d &vector1, const Vec3d &vector2)
Data structure for the representation of a 3D vector.
float Distance(const Vec2d &vector1, const Vec2d &vector2)
bool DetermineAffineTransformation(const Vec2d *pSourcePoints, const Vec2d *pTargetPoints, int nPoints, Mat3d &A, bool bUseSVD=false)
Determines an affine transformation based on a set of 2d-2d point correspondences.
bool RANSACHomography(const CDynamicArrayTemplate< PointPair2d > &matchCandidates, CDynamicArrayTemplate< PointPair2d > &resultMatches, float fRANSACThreshold=5.0f, int nIterations=500)
void SetVec(Vec3d &vec, float x, float y, float z)
void NormalizeVec(Vec3d &vec)
bool RANSACAffineTransformation(const CDynamicArrayTemplate< PointPair2d > &matchCandidates, CDynamicArrayTemplate< PointPair2d > &resultMatches, float fRANSACThreshold=5.0f, int nIterations=500)
void AddElement(const T &element)
Data structure for the representation of a 2D vector.
void SubtractVecVec(const Vec3d &vector1, const Vec3d &vector2, Vec3d &result)
void SetVec(Vec2d &vec, float x, float y)
void SetMat(Mat3d &matrix, float r1, float r2, float r3, float r4, float r5, float r6, float r7, float r8, float r9)
Data structure for the representation of a 3x3 matrix.
bool RANSAC3DPlane(const CVec3dArray &pointCandidates, CVec3dArray &resultPoints, float fRANSACThreshold=5.0f, int nIterations=500)