| 1 |
#include "colmap/scene/database_cache.h" |
| 2 |
|
| 3 |
#include "pycolmap/helpers.h" |
| 4 |
#include "pycolmap/pybind11_extension.h" |
| 5 |
#include "pycolmap/scene/types.h" |
| 6 |
|
| 7 |
#include <pybind11/eigen.h> |
| 8 |
#include <pybind11/pybind11.h> |
| 9 |
#include <pybind11/stl.h> |
| 10 |
|
| 11 |
using namespace colmap; |
| 12 |
using namespace pybind11::literals; |
| 13 |
namespace py = pybind11; |
| 14 |
|
| 15 |
void BindDatabaseCache(py::module& m) { |
| 16 |
using Opts = DatabaseCache::Options; |
| 17 |
auto PyOpts = py::classh<Opts>(m, "DatabaseCacheOptions"); |
| 18 |
PyOpts.def(py::init<>()) |
| 19 |
.def_readwrite("min_num_matches", |
| 20 |
&Opts::min_num_matches, |
| 21 |
"Only load image pairs with a minimum number of matches.") |
| 22 |
.def_readwrite("ignore_watermarks", |
| 23 |
&Opts::ignore_watermarks, |
| 24 |
"Whether to ignore watermark image pairs.") |
| 25 |
.def_readwrite("image_names", |
| 26 |
&Opts::image_names, |
| 27 |
"Only load the data for a subset of the images. " |
| 28 |
"All images are used if empty.") |
| 29 |
.def_readwrite( |
| 30 |
"load_all_images", |
| 31 |
&Opts::load_all_images, |
| 32 |
"Whether to load all candidate images regardless of whether they " |
| 33 |
"have correspondences. Only useful for triangulation.") |
| 34 |
.def_readwrite( |
| 35 |
"convert_pose_priors_to_enu", |
| 36 |
&Opts::convert_pose_priors_to_enu, |
| 37 |
"Whether to convert pose priors to ENU coordinate system."); |
| 38 |
|
| 39 |
MakeDataclass(PyOpts); |
| 40 |
|
| 41 |
py::classh<DatabaseCache> PyDatabaseCache(m, "DatabaseCache"); |
| 42 |
PyDatabaseCache.def(py::init<>()) |
| 43 |
.def_static("create", &DatabaseCache::Create, "database"_a, "options"_a) |
| 44 |
.def_static("create_from_cache", |
| 45 |
&DatabaseCache::CreateFromCache, |
| 46 |
"database_cache"_a, |
| 47 |
"options"_a) |
| 48 |
.def("load", &DatabaseCache::Load, "database"_a, "options"_a) |
| 49 |
.def("add_rig", &DatabaseCache::AddRig) |
| 50 |
.def("add_camera", &DatabaseCache::AddCamera) |
| 51 |
.def("add_frame", &DatabaseCache::AddFrame) |
| 52 |
.def("add_image", &DatabaseCache::AddImage) |
| 53 |
.def("add_pose_prior", &DatabaseCache::AddPosePrior) |
| 54 |
.def("num_rigs", &DatabaseCache::NumRigs) |
| 55 |
.def("num_cameras", &DatabaseCache::NumCameras) |
| 56 |
.def("num_frames", &DatabaseCache::NumFrames) |
| 57 |
.def("num_images", &DatabaseCache::NumImages) |
| 58 |
.def("num_pose_priors", &DatabaseCache::NumPosePriors) |
| 59 |
.def("exists_rig", &DatabaseCache::ExistsRig, "rig_id"_a) |
| 60 |
.def("exists_camera", &DatabaseCache::ExistsCamera, "camera_id"_a) |
| 61 |
.def("exists_frame", &DatabaseCache::ExistsFrame, "frame_id"_a) |
| 62 |
.def("exists_image", &DatabaseCache::ExistsImage, "image_id"_a) |
| 63 |
.def("rig", |
| 64 |
py::overload_cast<rig_t>(&DatabaseCache::Rig), |
| 65 |
py::return_value_policy::reference_internal, |
| 66 |
"rig_id"_a) |
| 67 |
.def("camera", |
| 68 |
py::overload_cast<camera_t>(&DatabaseCache::Camera), |
| 69 |
py::return_value_policy::reference_internal, |
| 70 |
"camera_id"_a) |
| 71 |
.def("frame", |
| 72 |
py::overload_cast<frame_t>(&DatabaseCache::Frame), |
| 73 |
py::return_value_policy::reference_internal, |
| 74 |
"frame_id"_a) |
| 75 |
.def("image", |
| 76 |
py::overload_cast<image_t>(&DatabaseCache::Image), |
| 77 |
py::return_value_policy::reference_internal, |
| 78 |
"image_id"_a) |
| 79 |
.def_property_readonly("rigs", |
| 80 |
&DatabaseCache::Rigs, |
| 81 |
py::return_value_policy::reference_internal) |
| 82 |
.def_property_readonly("cameras", |
| 83 |
&DatabaseCache::Cameras, |
| 84 |
py::return_value_policy::reference_internal) |
| 85 |
.def_property_readonly("frames", |
| 86 |
&DatabaseCache::Frames, |
| 87 |
py::return_value_policy::reference_internal) |
| 88 |
.def_property_readonly("images", |
| 89 |
&DatabaseCache::Images, |
| 90 |
py::return_value_policy::reference_internal) |
| 91 |
.def_property_readonly("pose_priors", &DatabaseCache::PosePriors) |
| 92 |
.def_property_readonly( |
| 93 |
"correspondence_graph", |
| 94 |
static_cast<std::shared_ptr<const class CorrespondenceGraph> ( |
| 95 |
DatabaseCache::*)() const>(&DatabaseCache::CorrespondenceGraph)) |
| 96 |
.def("find_image_with_name", &DatabaseCache::FindImageWithName, "name"_a); |
| 97 |
} |