| 1 |
#include "colmap/scene/synthetic.h" |
| 2 |
|
| 3 |
#include "pycolmap/helpers.h" |
| 4 |
#include "pycolmap/pybind11_extension.h" |
| 5 |
#include "pycolmap/utils.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 BindSynthetic(py::module& m) { |
| 16 |
auto PySyntheticMatchConfig = |
| 17 |
py::enum_<SyntheticDatasetOptions::MatchConfig>( |
| 18 |
m, "SyntheticDatasetMatchConfig") |
| 19 |
.value("EXHAUSTIVE", SyntheticDatasetOptions::MatchConfig::EXHAUSTIVE) |
| 20 |
.value("CHAINED", SyntheticDatasetOptions::MatchConfig::CHAINED) |
| 21 |
.value("SPARSE", SyntheticDatasetOptions::MatchConfig::SPARSE); |
| 22 |
AddStringToEnumConstructor(PySyntheticMatchConfig); |
| 23 |
|
| 24 |
auto PySyntheticDatasetOptions = |
| 25 |
py::classh<SyntheticDatasetOptions>(m, "SyntheticDatasetOptions") |
| 26 |
.def(py::init<>()) |
| 27 |
.def_readwrite("feature_type", |
| 28 |
&SyntheticDatasetOptions::feature_type, |
| 29 |
"The type of feature descriptors to synthesize.") |
| 30 |
.def_readwrite("num_rigs", &SyntheticDatasetOptions::num_rigs) |
| 31 |
.def_readwrite("num_cameras_per_rig", |
| 32 |
&SyntheticDatasetOptions::num_cameras_per_rig) |
| 33 |
.def_readwrite("num_frames_per_rig", |
| 34 |
&SyntheticDatasetOptions::num_frames_per_rig) |
| 35 |
.def_readwrite("num_points3D", &SyntheticDatasetOptions::num_points3D) |
| 36 |
.def_readwrite("track_length", |
| 37 |
&SyntheticDatasetOptions::track_length, |
| 38 |
"Target track length per 3D point. -1 = dense " |
| 39 |
"visibility (default), >= 2 = pruned observations.") |
| 40 |
.def_readwrite( |
| 41 |
"sensor_from_rig_translation_stddev", |
| 42 |
&SyntheticDatasetOptions::sensor_from_rig_translation_stddev) |
| 43 |
.def_readwrite( |
| 44 |
"sensor_from_rig_rotation_stddev", |
| 45 |
&SyntheticDatasetOptions::sensor_from_rig_rotation_stddev, |
| 46 |
"Random rotation in degrees around the z-axis of the sensor.") |
| 47 |
.def_readwrite("camera_width", &SyntheticDatasetOptions::camera_width) |
| 48 |
.def_readwrite("camera_height", |
| 49 |
&SyntheticDatasetOptions::camera_height) |
| 50 |
.def_readwrite("camera_model_id", |
| 51 |
&SyntheticDatasetOptions::camera_model_id) |
| 52 |
.def_readwrite("camera_params", |
| 53 |
&SyntheticDatasetOptions::camera_params) |
| 54 |
.def_readwrite( |
| 55 |
"camera_has_prior_focal_length", |
| 56 |
&SyntheticDatasetOptions::camera_has_prior_focal_length) |
| 57 |
.def_readwrite("num_points2D_without_point3D", |
| 58 |
&SyntheticDatasetOptions::num_points2D_without_point3D) |
| 59 |
.def_readwrite("inlier_match_ratio", |
| 60 |
&SyntheticDatasetOptions::inlier_match_ratio) |
| 61 |
.def_readwrite( |
| 62 |
"two_view_geometry_has_relative_pose", |
| 63 |
&SyntheticDatasetOptions::two_view_geometry_has_relative_pose, |
| 64 |
"Whether to include decomposed relative poses in two-view " |
| 65 |
"geometries.") |
| 66 |
.def_readwrite("match_config", &SyntheticDatasetOptions::match_config) |
| 67 |
.def_readwrite("match_sparsity", |
| 68 |
&SyntheticDatasetOptions::match_sparsity, |
| 69 |
"Sparsity parameter for SPARSE match config [0,1].") |
| 70 |
.def_readwrite("prior_position", |
| 71 |
&SyntheticDatasetOptions::prior_position) |
| 72 |
.def_readwrite("prior_gravity", |
| 73 |
&SyntheticDatasetOptions::prior_gravity) |
| 74 |
.def_readwrite( |
| 75 |
"prior_position_coordinate_system", |
| 76 |
&SyntheticDatasetOptions::prior_position_coordinate_system) |
| 77 |
.def_readwrite("prior_gravity_in_world", |
| 78 |
&SyntheticDatasetOptions::prior_gravity_in_world, |
| 79 |
"Prior gravity direction in world coordinates."); |
| 80 |
MakeDataclass(PySyntheticDatasetOptions); |
| 81 |
|
| 82 |
m.def( |
| 83 |
"synthesize_dataset", |
| 84 |
[](const SyntheticDatasetOptions& options, Database* database = nullptr) { |
| 85 |
Reconstruction reconstruction; |
| 86 |
SynthesizeDataset(options, &reconstruction, database); |
| 87 |
return reconstruction; |
| 88 |
}, |
| 89 |
"options"_a, |
| 90 |
"database"_a = py::none()); |
| 91 |
|
| 92 |
auto PySyntheticNoiseOptions = |
| 93 |
py::classh<SyntheticNoiseOptions>(m, "SyntheticNoiseOptions") |
| 94 |
.def(py::init<>()) |
| 95 |
.def_readwrite( |
| 96 |
"rig_from_world_translation_stddev", |
| 97 |
&SyntheticNoiseOptions::rig_from_world_translation_stddev) |
| 98 |
.def_readwrite( |
| 99 |
"rig_from_world_rotation_stddev", |
| 100 |
&SyntheticNoiseOptions::rig_from_world_rotation_stddev, |
| 101 |
"Random rotation in degrees around the z-axis of the rig.") |
| 102 |
.def_readwrite("point3D_stddev", |
| 103 |
&SyntheticNoiseOptions::point3D_stddev) |
| 104 |
.def_readwrite("point2D_stddev", |
| 105 |
&SyntheticNoiseOptions::point2D_stddev) |
| 106 |
.def_readwrite("prior_position_stddev", |
| 107 |
&SyntheticNoiseOptions::prior_position_stddev) |
| 108 |
.def_readwrite("prior_gravity_stddev", |
| 109 |
&SyntheticNoiseOptions::prior_gravity_stddev); |
| 110 |
MakeDataclass(PySyntheticNoiseOptions); |
| 111 |
|
| 112 |
m.def("synthesize_noise", |
| 113 |
&SynthesizeNoise, |
| 114 |
"options"_a, |
| 115 |
"reconstruction"_a, |
| 116 |
"database"_a = py::none()); |
| 117 |
|
| 118 |
auto PySyntheticImageOptions = |
| 119 |
py::classh<SyntheticImageOptions>(m, "SyntheticImageOptions") |
| 120 |
.def(py::init<>()) |
| 121 |
.def_readwrite("feature_peak_radius", |
| 122 |
&SyntheticImageOptions::feature_peak_radius) |
| 123 |
.def_readwrite( |
| 124 |
"feature_patch_radius", |
| 125 |
&SyntheticImageOptions::feature_patch_radius, |
| 126 |
"Random rotation in degrees around the z-axis of the rig.") |
| 127 |
.def_readwrite("feature_patch_max_brightness", |
| 128 |
&SyntheticImageOptions::feature_patch_max_brightness); |
| 129 |
MakeDataclass(PySyntheticImageOptions); |
| 130 |
|
| 131 |
m.def("synthesize_images", |
| 132 |
&SynthesizeImages, |
| 133 |
"options"_a, |
| 134 |
"reconstruction"_a, |
| 135 |
"image_path"_a); |
| 136 |
} |