22RansacHomography::RansacHomography (
Options const& options)
33 <<
" iterations, threshold " << this->opts.
threshold
34 <<
"..." << std::endl;
37 std::vector<int> inliers;
38 inliers.reserve(matches.size());
39 for (
int iteration = 0; iteration < this->opts.
max_iterations; ++iteration)
42 this->compute_homography(matches, &homography);
43 this->evaluate_homography(matches, homography, &inliers);
44 if (inliers.size() > result->
inliers.size())
48 std::cout <<
"RANSAC-H: Iteration " << iteration
49 <<
", inliers " << inliers.size() <<
" ("
50 << (100.0 * inliers.size() / matches.size())
56 inliers.reserve(matches.size());
65 if (matches.size() < 4)
66 throw std::invalid_argument(
"At least 4 matches required");
73 while (result.size() < 4)
77 std::set<int>::const_iterator iter = result.begin();
78 for (std::size_t i = 0; i < 4; ++i, ++iter)
79 four_correspondeces[i] = matches[*iter];
82 *homography /= (*homography)[8];
91 for (std::size_t i = 0; i < matches.size(); ++i)
93 Correspondence2D2D
const& match = matches[i];
95 if (error < square_threshold)
96 inliers->push_back(i);
void estimate(Correspondences2D2D const &matches, Result *result)
bool homography_dlt(Correspondences2D2D const &points, HomographyMatrix *result)
Direct linear transformation algorithm to compute the homography matrix from image correspondences.
math::Matrix3d HomographyMatrix
std::vector< Correspondence2D2D > Correspondences2D2D
double symmetric_transfer_error(HomographyMatrix const &homography, Correspondence2D2D const &match)
Computes the symmetric transfer error for an image correspondence given the homography matrix between...
void swap(mve::Image< T > &a, mve::Image< T > &b)
Specialization of std::swap for efficient image swapping.
int rand_int(void)
Returns a random number in [0, 2^31].
#define SFM_NAMESPACE_END
#define SFM_NAMESPACE_BEGIN
double threshold
Threshold used to determine inliers.
int max_iterations
The number of RANSAC iterations.
bool verbose_output
Produce status messages on the console.
HomographyMatrix homography
The resulting homography matrix which led to the inliers.
std::vector< int > inliers
The indices of inliers in the correspondences which led to the homography matrix.