#include "colmap/estimators/solvers/fundamental_matrix.h" #include "colmap/math/random.h" #include "colmap/optim/loransac.h" #include "colmap/optim/support_measurement.h" #include "colmap/scene/camera.h" #include "colmap/util/logging.h" #include "pycolmap/helpers.h" #include "pycolmap/pybind11_extension.h" #include "pycolmap/utils.h" #include #include #include using namespace colmap; using namespace pybind11::literals; namespace py = pybind11; py::typing::Optional PyEstimateFundamentalMatrix( const std::vector& points2D1, const std::vector& points2D2, const RANSACOptions& options, const bool use_sampson_refinement) { py::gil_scoped_release release; THROW_CHECK_EQ(points2D1.size(), points2D2.size()); const auto report = use_sampson_refinement ? LORANSAC(options) .Estimate(points2D1, points2D2) : LORANSAC(options) .Estimate(points2D1, points2D2); py::gil_scoped_acquire acquire; if (!report.success) { return py::none(); } return py::dict("F"_a = report.model, "num_inliers"_a = report.support.num_inliers, "inlier_mask"_a = ToPythonMask(report.inlier_mask)); } void BindFundamentalMatrixEstimator(py::module& m) { auto ransac_options = m.attr("RANSACOptions")().cast(); m.def("estimate_fundamental_matrix", &PyEstimateFundamentalMatrix, "points2D1"_a, "points2D2"_a, py::arg_v("estimation_options", ransac_options, "RANSACOptions()"), "use_sampson_refinement"_a = true, "Robustly estimate fundamental matrix with LO-RANSAC."); }