| 1 |
#include "colmap/scene/pose_graph.h" |
| 2 |
|
| 3 |
#include "colmap/util/hash_containers.h" |
| 4 |
|
| 5 |
#include "pycolmap/helpers.h" |
| 6 |
#include "pycolmap/pybind11_extension.h" |
| 7 |
#include "pycolmap/scene/types.h" |
| 8 |
|
| 9 |
#include <pybind11/pybind11.h> |
| 10 |
#include <pybind11/stl.h> |
| 11 |
#include <pybind11/stl_bind.h> |
| 12 |
|
| 13 |
using namespace colmap; |
| 14 |
using namespace pybind11::literals; |
| 15 |
namespace py = pybind11; |
| 16 |
|
| 17 |
void BindPoseGraph(py::module& m) { |
| 18 |
auto PyPoseGraphEdge = |
| 19 |
py::classh<PoseGraph::Edge>(m, "PoseGraphEdge") |
| 20 |
.def(py::init<>()) |
| 21 |
.def(py::init<const Rigid3d&>(), "cam2_from_cam1"_a) |
| 22 |
.def_readwrite("cam2_from_cam1", |
| 23 |
&PoseGraph::Edge::cam2_from_cam1, |
| 24 |
"Relative pose from image 1 to image 2.") |
| 25 |
.def_readwrite("num_matches", |
| 26 |
&PoseGraph::Edge::num_matches, |
| 27 |
"Number of two-view matches used to compute the " |
| 28 |
"relative pose.") |
| 29 |
.def_readwrite("valid", |
| 30 |
&PoseGraph::Edge::valid, |
| 31 |
"Whether this edge is valid for reconstruction.") |
| 32 |
.def("invert", |
| 33 |
&PoseGraph::Edge::Invert, |
| 34 |
"Invert the geometry to match swapped image order."); |
| 35 |
MakeDataclass(PyPoseGraphEdge); |
| 36 |
|
| 37 |
py::bind_map<PoseGraphEdgeMap>(m, "PoseGraphEdgeMap"); |
| 38 |
|
| 39 |
py::classh<PoseGraph>(m, "PoseGraph") |
| 40 |
.def(py::init<>()) |
| 41 |
.def_property_readonly("edges", |
| 42 |
py::overload_cast<>(&PoseGraph::Edges), |
| 43 |
py::return_value_policy::reference_internal, |
| 44 |
"Access to all edges in the pose graph.") |
| 45 |
.def_property_readonly("num_edges", |
| 46 |
&PoseGraph::NumEdges, |
| 47 |
"Number of edges in the pose graph.") |
| 48 |
.def_property_readonly( |
| 49 |
"empty", &PoseGraph::Empty, "Whether the pose graph has no edges.") |
| 50 |
.def("clear", &PoseGraph::Clear, "Remove all edges.") |
| 51 |
.def("load", |
| 52 |
&PoseGraph::Load, |
| 53 |
"corr_graph"_a, |
| 54 |
"Load edges from a correspondence graph.") |
| 55 |
.def("add_edge", |
| 56 |
&PoseGraph::AddEdge, |
| 57 |
"image_id1"_a, |
| 58 |
"image_id2"_a, |
| 59 |
"edge"_a, |
| 60 |
py::return_value_policy::reference_internal, |
| 61 |
"Add a new edge between two images. Throws if edge already exists.") |
| 62 |
.def("has_edge", |
| 63 |
&PoseGraph::HasEdge, |
| 64 |
"image_id1"_a, |
| 65 |
"image_id2"_a, |
| 66 |
"Check if an edge exists between two images.") |
| 67 |
.def("get_edge", |
| 68 |
&PoseGraph::GetEdge, |
| 69 |
"image_id1"_a, |
| 70 |
"image_id2"_a, |
| 71 |
"Get a copy of the edge between two images. Automatically handles " |
| 72 |
"geometric inversion if image order was swapped.") |
| 73 |
.def("delete_edge", |
| 74 |
&PoseGraph::DeleteEdge, |
| 75 |
"image_id1"_a, |
| 76 |
"image_id2"_a, |
| 77 |
"Delete the edge between two images. Returns True if deleted.") |
| 78 |
.def("update_edge", |
| 79 |
&PoseGraph::UpdateEdge, |
| 80 |
"image_id1"_a, |
| 81 |
"image_id2"_a, |
| 82 |
"edge"_a, |
| 83 |
"Update an existing edge. Throws if edge does not exist.") |
| 84 |
.def("is_valid", |
| 85 |
&PoseGraph::IsValid, |
| 86 |
"pair_id"_a, |
| 87 |
"Check if an edge is marked as valid.") |
| 88 |
.def("set_valid_edge", |
| 89 |
&PoseGraph::SetValidEdge, |
| 90 |
"pair_id"_a, |
| 91 |
"Mark an edge as valid.") |
| 92 |
.def("set_invalid_edge", |
| 93 |
&PoseGraph::SetInvalidEdge, |
| 94 |
"pair_id"_a, |
| 95 |
"Mark an edge as invalid.") |
| 96 |
.def("largest_connected_frame_component", |
| 97 |
&PoseGraph::LargestConnectedFrameComponent, |
| 98 |
"reconstruction"_a, |
| 99 |
"filter_unregistered"_a = true, |
| 100 |
"Return the largest connected component of frames. If " |
| 101 |
"filter_unregistered is True, only consider frames with poses.") |
| 102 |
.def("invalidate_pairs_outside_active_image_ids", |
| 103 |
&PoseGraph::InvalidatePairsOutsideActiveImageIds, |
| 104 |
"active_image_ids"_a, |
| 105 |
"Mark image pairs as invalid if either image is not in the active " |
| 106 |
"set."); |
| 107 |
} |