Skip to content

Commit 2ac963c

Browse files
authored
Merge pull request #6 from Kotochleb/feature/expose-more-objects
Expose more M3T functionalities to the python bindings
2 parents 6901f2f + 559862c commit 2ac963c

File tree

2 files changed

+92
-3
lines changed

2 files changed

+92
-3
lines changed

src/pym3t.cpp

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,13 @@ PYBIND11_MODULE(_pym3t_mod, m) {
6666
.def("AddViewer", &Tracker::AddViewer)
6767
.def("AddDetector", &Tracker::AddDetector)
6868
.def("AddOptimizer", &Tracker::AddOptimizer)
69+
.def("ClearOptimizers", &Tracker::ClearOptimizers)
6970
.def_property("name", &Tracker::name, &Tracker::set_name)
7071
.def_property("n_corr_iterations", &Tracker::n_corr_iterations, &Tracker::set_n_corr_iterations)
7172
.def_property("n_update_iterations", &Tracker::n_update_iterations, &Tracker::set_n_update_iterations)
73+
.def_property_readonly("set_up", &Tracker::set_up)
74+
.def_property_readonly("optimizers", &Tracker::optimizer_ptrs)
75+
.def_property_readonly("modalities", &Tracker::modality_ptrs)
7276
;
7377

7478
//--------------------------//
@@ -119,25 +123,29 @@ PYBIND11_MODULE(_pym3t_mod, m) {
119123
#ifdef PYM3T_WITH_REALSENSE
120124
// RealSenseColorCamera
121125
py::class_<RealSenseColorCamera, ColorCamera, std::shared_ptr<RealSenseColorCamera>>(m, "RealSenseColorCamera")
126+
.def("SetUp", &RealSenseColorCamera::SetUp)
122127
.def(py::init<const std::string &, bool>(), "name"_a, "use_depth_as_world_frame"_a=false)
123128
;
124129

125130
// RealSenseDepthCamera
126131
py::class_<RealSenseDepthCamera, DepthCamera, std::shared_ptr<RealSenseDepthCamera>>(m, "RealSenseDepthCamera")
132+
.def("SetUp", &RealSenseDepthCamera::SetUp)
127133
.def(py::init<const std::string &, bool>(), "name"_a, "use_color_as_world_frame"_a=true)
128134
;
129135
#endif
130136

131137
// DummyColorCamera
132138
py::class_<DummyColorCamera, ColorCamera, std::shared_ptr<DummyColorCamera>>(m, "DummyColorCamera")
133139
.def(py::init<const std::string &>(), "name"_a)
140+
.def("SetUp", &DummyColorCamera::SetUp)
134141
.def_property("image", &Camera::image, &DummyColorCamera::set_image)
135142
.def_property("intrinsics", &DummyColorCamera::get_intrinsics, &DummyColorCamera::set_intrinsics)
136143
;
137144

138145
// DummyDepthCamera
139146
py::class_<DummyDepthCamera, DepthCamera, std::shared_ptr<DummyDepthCamera>>(m, "DummyDepthCamera")
140147
.def(py::init<const std::string &, float>(), "name"_a, "depth_scale"_a=0.001)
148+
.def("SetUp", &DummyDepthCamera::SetUp)
141149
.def_property("image", &Camera::image, &DummyDepthCamera::set_image)
142150
.def_property("intrinsics", &DummyDepthCamera::get_intrinsics, &DummyDepthCamera::set_intrinsics)
143151
.def_property("depth_scale", &DummyDepthCamera::depth_scale, &DummyDepthCamera::set_depth_scale)
@@ -148,6 +156,7 @@ PYBIND11_MODULE(_pym3t_mod, m) {
148156
// RendererGeometry
149157
py::class_<RendererGeometry, std::shared_ptr<RendererGeometry>>(m, "RendererGeometry")
150158
.def(py::init<const std::string &>(), "name"_a)
159+
.def("SetUp", &RendererGeometry::SetUp)
151160
.def("AddBody", &RendererGeometry::AddBody)
152161
.def("DeleteBody", &RendererGeometry::DeleteBody)
153162
.def("ClearBodies", &RendererGeometry::ClearBodies)
@@ -191,6 +200,7 @@ PYBIND11_MODULE(_pym3t_mod, m) {
191200
py::class_<NormalDepthViewer, Viewer, std::shared_ptr<NormalDepthViewer>>(m, "NormalDepthViewer")
192201
.def(py::init<const std::string &, const std::shared_ptr<DepthCamera> &, const std::shared_ptr<RendererGeometry> &, float, float, float>(),
193202
"name"_a, "depth_camera_ptr"_a, "renderer_geometry_ptr"_a, "min_depth"_a=0.0f, "max_depth"_a=1.0f, "opacity"_a=0.5f)
203+
.def("SetUp", &NormalDepthViewer::SetUp)
194204
.def("UpdateViewer", &NormalDepthViewer::UpdateViewer, "save_index"_a)
195205
.def("set_opacity", &NormalDepthViewer::set_opacity, "opacity"_a)
196206
;
@@ -210,6 +220,7 @@ PYBIND11_MODULE(_pym3t_mod, m) {
210220
py::class_<FocusedBasicDepthRenderer, FocusedDepthRenderer, std::shared_ptr<FocusedBasicDepthRenderer>>(m, "FocusedBasicDepthRenderer")
211221
.def(py::init<const std::string &, const std::shared_ptr<RendererGeometry> &, const std::shared_ptr<Camera> &, int, float, float>(),
212222
"name"_a, "renderer_geometry_ptr"_a, "camera_ptr"_a, "image_size"_a=200, "z_min"_a=0.01f, "z_max"_a=5.0f)
223+
.def("SetUp", &FocusedBasicDepthRenderer::SetUp)
213224
.def("AddReferencedBody", &FocusedBasicDepthRenderer::AddReferencedBody)
214225
;
215226

@@ -219,6 +230,7 @@ PYBIND11_MODULE(_pym3t_mod, m) {
219230
"name"_a, "renderer_geometry_ptr"_a, "camera_ptr"_a, "id_type"_a=IDType::BODY, "image_size"_a=200, "z_min"_a=0.01f, "z_max"_a=5.0f)
220231
.def(py::init<const std::string &, const std::filesystem::path&, const std::shared_ptr<RendererGeometry> &, const std::shared_ptr<Camera>&>(),
221232
"name"_a, "metafile_path"_a, "renderer_geometry_ptr"_a, "camera_ptr"_a)
233+
.def("SetUp", &FocusedSilhouetteRenderer::SetUp)
222234
.def("AddReferencedBody", &FocusedSilhouetteRenderer::AddReferencedBody)
223235
;
224236

@@ -230,6 +242,7 @@ PYBIND11_MODULE(_pym3t_mod, m) {
230242
.def(py::init<const std::string &, const std::filesystem::path &, float, bool, bool, const Transform3fA &>(),
231243
"name"_a, "geometry_path"_a, "geometry_unit_in_meter"_a, "geometry_counterclockwise"_a, "geometry_enable_culling"_a, "geometry2body_pose"_a)
232244
.def(py::init<const std::string &, const std::filesystem::path &>(), "name"_a, "metafile_path"_a)
245+
.def("SetUp", &Body::SetUp)
233246
.def_property("name", &Body::name, &Body::set_name)
234247
.def_property("geometry_path", &Body::geometry_path, &Body::set_geometry_path)
235248
.def_property("metafile_path", &Body::metafile_path, &Body::set_metafile_path)
@@ -250,9 +263,11 @@ PYBIND11_MODULE(_pym3t_mod, m) {
250263
"body2joint_pose"_a=Transform3fA::Identity(), "joint2parent_pose"_a=Transform3fA::Identity(), "link2world_pose"_a=Transform3fA::Identity(),
251264
"free_directions"_a=std::array<bool, 6>({true, true, true, true, true, true}), "fixed_body2joint_pose"_a=true)
252265
.def(py::init<const std::string &, const std::filesystem::path &, const std::shared_ptr<Body> &>(), "name"_a, "metafile_path"_a, "body_ptr"_a)
266+
.def("SetUp", &Link::SetUp)
253267
.def("AddModality", &Link::AddModality)
254268
.def("CalculateGradientAndHessian", &Link::CalculateGradientAndHessian)
255269
.def_property("name", &Link::name, &Link::set_name)
270+
.def_property("body", &Link::body_ptr, &Link::set_body_ptr)
256271
.def_property("link2world_pose", &Link::link2world_pose, &Link::set_link2world_pose)
257272
.def_property_readonly("modalities", &Link::modality_ptrs)
258273
.def("gradient", &Link::gradient)
@@ -274,6 +289,7 @@ PYBIND11_MODULE(_pym3t_mod, m) {
274289

275290
// Detector
276291
py::class_<Detector, PyDetector, std::shared_ptr<Detector>>(m, "Detector")
292+
.def("SetUp", &Detector::SetUp)
277293
.def_property("name", &Detector::name, &Detector::set_name)
278294
;
279295

@@ -289,12 +305,27 @@ PYBIND11_MODULE(_pym3t_mod, m) {
289305

290306
//--------------------------//
291307

308+
// ColorHistograms
309+
py::class_<ColorHistograms, std::shared_ptr<ColorHistograms>>(m, "ColorHistograms")
310+
.def(py::init<const std::string &, int, float, float>(),
311+
"name"_a,
312+
"n_bins"_a=16, "learning_rate_f"_a=0.2f, "learning_rate_b"_a=0.2f)
313+
.def("SetUp", &ColorHistograms::SetUp)
314+
.def_property("name", &ColorHistograms::name, &ColorHistograms::set_name)
315+
.def_property("n_bins", &ColorHistograms::n_bins, &ColorHistograms::set_n_bins)
316+
.def_property("learning_rate_f", &ColorHistograms::learning_rate_f, &ColorHistograms::set_learning_rate_f)
317+
.def_property("learning_rate_b", &ColorHistograms::learning_rate_b, &ColorHistograms::set_learning_rate_b)
318+
;
319+
320+
//--------------------------//
321+
292322
// RegionModel
293323
py::class_<RegionModel, std::shared_ptr<RegionModel>>(m, "RegionModel")
294324
.def(py::init<const std::string &, const std::shared_ptr<Body> &, const std::filesystem::path &,
295325
float, int, int, float, float, bool, int>(),
296326
"name"_a, "body_ptr"_a, "model_path"_a,
297327
"sphere_radius"_a=0.8f, "n_divides"_a=4, "n_points_max"_a=200, "max_radius_depth_offset"_a=0.05f, "stride_depth_offset"_a=0.002f, "use_random_seed"_a=false, "image_size"_a=2000)
328+
.def("SetUp", &RegionModel::SetUp)
298329
.def_property("name", &RegionModel::name, &RegionModel::set_name)
299330
;
300331

@@ -304,6 +335,7 @@ PYBIND11_MODULE(_pym3t_mod, m) {
304335
float, int, int, float, float, bool, int>(),
305336
"name"_a, "body_ptr"_a, "model_path"_a,
306337
"sphere_radius"_a=0.8f, "n_divides"_a=4, "n_points_max"_a=200, "max_radius_depth_offset"_a=0.05f, "stride_depth_offset"_a=0.002f, "use_random_seed"_a=false, "image_size"_a=2000)
338+
.def("SetUp", &DepthModel::SetUp)
307339
.def_property("name", &DepthModel::name, &DepthModel::set_name)
308340
;
309341

@@ -335,6 +367,7 @@ PYBIND11_MODULE(_pym3t_mod, m) {
335367

336368
// Modality -> not constructible, just to enable automatic downcasting and binding of child classes
337369
py::class_<Modality, PyModality, std::shared_ptr<Modality>>(m, "Modality")
370+
.def("SetUp", &Modality::SetUp)
338371
.def_property_readonly("gradient", &Modality::gradient)
339372
.def_property_readonly("hessian", &Modality::hessian)
340373
.def_property("name", &Modality::name, &Modality::set_name)
@@ -344,6 +377,7 @@ PYBIND11_MODULE(_pym3t_mod, m) {
344377
py::class_<RegionModality, Modality, std::shared_ptr<RegionModality>>(m, "RegionModality")
345378
.def(py::init<const std::string &, const std::shared_ptr<Body> &, const std::shared_ptr<ColorCamera> &, const std::shared_ptr<RegionModel> &>(),
346379
"name"_a, "body_ptr"_a, "color_camera_ptr"_a, "region_model_ptr"_a)
380+
.def("SetUp", &RegionModality::SetUp)
347381
.def_property("n_lines_max", &RegionModality::n_lines_max, &RegionModality::set_n_lines_max)
348382
.def_property("use_adaptive_coverage", &RegionModality::use_adaptive_coverage, &RegionModality::set_use_adaptive_coverage)
349383
.def_property("reference_contour_length", &RegionModality::reference_contour_length, &RegionModality::set_reference_contour_length)
@@ -357,6 +391,9 @@ PYBIND11_MODULE(_pym3t_mod, m) {
357391
.def_property("scales", &RegionModality::scales, &RegionModality::set_scales)
358392
.def_property("standard_deviations", &RegionModality::standard_deviations, &RegionModality::set_standard_deviations)
359393

394+
.def("UseSharedColorHistograms", &RegionModality::UseSharedColorHistograms, "color_histograms_ptr"_a)
395+
.def("DoNotUseSharedColorHistograms", &RegionModality::DoNotUseSharedColorHistograms)
396+
360397
.def_property("n_histogram_bins", &RegionModality::n_histogram_bins, &RegionModality::set_n_histogram_bins)
361398
.def_property("learning_rate_f", &RegionModality::learning_rate_f, &RegionModality::set_learning_rate_f)
362399
.def_property("learning_rate_b", &RegionModality::learning_rate_b, &RegionModality::set_learning_rate_b)
@@ -393,6 +430,7 @@ PYBIND11_MODULE(_pym3t_mod, m) {
393430
py::class_<DepthModality, Modality, std::shared_ptr<DepthModality>>(m, "DepthModality")
394431
.def(py::init<const std::string &, const std::shared_ptr<Body> &, const std::shared_ptr<DepthCamera> &, const std::shared_ptr<DepthModel> &>(),
395432
"name"_a, "body_ptr"_a, "depth_camera_ptr"_a, "depth_model_ptr"_a)
433+
.def("SetUp", &DepthModality::SetUp)
396434

397435
.def_property("n_points_max", &DepthModality::n_points_max, &DepthModality::set_n_points_max)
398436
.def_property("use_adaptive_coverage", &DepthModality::use_adaptive_coverage, &DepthModality::set_use_adaptive_coverage)
@@ -420,16 +458,64 @@ PYBIND11_MODULE(_pym3t_mod, m) {
420458
.def_property("visualize_points_result", &DepthModality::visualize_points_result, &DepthModality::set_visualize_points_result)
421459
;
422460

461+
py::enum_<TextureModality::DescriptorType>(m, "DescriptorType")
462+
.value("BRISK", TextureModality::DescriptorType::BRISK)
463+
.value("DAISY", TextureModality::DescriptorType::DAISY)
464+
.value("FREAK", TextureModality::DescriptorType::FREAK)
465+
.value("SIFT", TextureModality::DescriptorType::SIFT)
466+
.value("ORB", TextureModality::DescriptorType::ORB)
467+
#ifdef USE_CUDA
468+
.value("ORB_CUDA", TextureModality::DescriptorType::ORB_CUDA)
469+
#endif
470+
.export_values();
471+
423472

424473
// TextureModality
425474
py::class_<TextureModality, Modality, std::shared_ptr<TextureModality>>(m, "TextureModality")
426475
.def(py::init<const std::string &, const std::shared_ptr<Body> &, const std::shared_ptr<ColorCamera> &, const std::shared_ptr<FocusedSilhouetteRenderer>&>(),
427476
"name"_a, "body_ptr"_a, "color_camera_ptr"_a, "silhouette_renderer_ptr"_a)
428477
.def(py::init<const std::string &, const std::filesystem::path &, const std::shared_ptr<Body> &, const std::shared_ptr<ColorCamera> &, const std::shared_ptr<FocusedSilhouetteRenderer>&>(),
429478
"name"_a, "metafile_path"_a, "body_ptr"_a, "color_camera_ptr"_a, "silhouette_renderer_ptr"_a)
479+
.def("SetUp", &TextureModality::SetUp)
430480

431481
.def("ModelOcclusions", &TextureModality::ModelOcclusions)
432482
.def("MeasureOcclusions", &TextureModality::MeasureOcclusions)
483+
484+
.def_property("descriptor_type", &TextureModality::descriptor_type, &TextureModality::set_descriptor_type)
485+
.def_property("focused_image_size", &TextureModality::focused_image_size, &TextureModality::set_focused_image_size)
486+
.def_property("descriptor_distance_threshold", &TextureModality::descriptor_distance_threshold, &TextureModality::set_descriptor_distance_threshold)
487+
.def_property("tukey_norm_constant", &TextureModality::tukey_norm_constant, &TextureModality::set_tukey_norm_constant)
488+
.def_property("standard_deviations", &TextureModality::standard_deviations, &TextureModality::set_standard_deviations)
489+
.def_property("max_keyframe_rotation_difference", &TextureModality::max_keyframe_rotation_difference, &TextureModality::set_max_keyframe_rotation_difference)
490+
.def_property("max_keyframe_age", &TextureModality::max_keyframe_age, &TextureModality::set_max_keyframe_age)
491+
.def_property("n_keyframes", &TextureModality::n_keyframes, &TextureModality::set_n_keyframes)
492+
493+
.def_property("orb_n_features", &TextureModality::orb_n_features, &TextureModality::set_orb_n_features)
494+
.def_property("orb_scale_factor", &TextureModality::orb_scale_factor, &TextureModality::set_orb_scale_factor)
495+
.def_property("orb_n_levels", &TextureModality::orb_n_levels, &TextureModality::set_orb_n_levels)
496+
.def_property("brisk_threshold", &TextureModality::brisk_threshold, &TextureModality::set_brisk_threshold)
497+
.def_property("brisk_octave", &TextureModality::brisk_octave, &TextureModality::set_brisk_octave)
498+
.def_property("brisk_pattern_scale", &TextureModality::brisk_pattern_scale, &TextureModality::set_brisk_pattern_scale)
499+
.def_property("daisy_radius", &TextureModality::daisy_radius, &TextureModality::set_daisy_radius)
500+
.def_property("daisy_q_radius", &TextureModality::daisy_q_radius, &TextureModality::set_daisy_q_radius)
501+
.def_property("daisy_q_theta", &TextureModality::daisy_q_theta, &TextureModality::set_daisy_q_theta)
502+
.def_property("daisy_q_hist", &TextureModality::daisy_q_hist, &TextureModality::set_daisy_q_hist)
503+
.def_property("freak_orientation_normalized", &TextureModality::freak_orientation_normalized, &TextureModality::set_freak_orientation_normalized)
504+
.def_property("freak_scale_normalized", &TextureModality::freak_scale_normalized, &TextureModality::set_freak_scale_normalized)
505+
.def_property("freak_pattern_scale", &TextureModality::freak_pattern_scale, &TextureModality::set_freak_pattern_scale)
506+
.def_property("freak_n_octaves", &TextureModality::freak_n_octaves, &TextureModality::set_freak_n_octaves)
507+
.def_property("sift_n_features", &TextureModality::sift_n_features, &TextureModality::set_sift_n_features)
508+
.def_property("sift_n_octave_layers", &TextureModality::sift_n_octave_layers, &TextureModality::set_sift_n_octave_layers)
509+
.def_property("sift_contrast_threshold", &TextureModality::sift_contrast_threshold, &TextureModality::set_sift_contrast_threshold)
510+
.def_property("sift_edge_threshold", &TextureModality::sift_edge_threshold, &TextureModality::set_sift_edge_threshold)
511+
.def_property("sift_sigma", &TextureModality::sift_sigma, &TextureModality::set_sift_sigma)
512+
513+
.def_property("measured_occlusion_radius", &TextureModality::measured_occlusion_radius, &TextureModality::set_measured_occlusion_radius)
514+
.def_property("measured_occlusion_threshold", &TextureModality::measured_occlusion_threshold, &TextureModality::set_measured_occlusion_threshold)
515+
.def_property("modeled_occlusion_radius", &TextureModality::modeled_occlusion_radius, &TextureModality::set_modeled_occlusion_radius)
516+
.def_property("modeled_occlusion_threshold", &TextureModality::modeled_occlusion_threshold, &TextureModality::set_modeled_occlusion_threshold)
517+
518+
433519
;
434520

435521
// Optimizer
@@ -441,6 +527,7 @@ PYBIND11_MODULE(_pym3t_mod, m) {
441527
.def_property("metafile_path", &Optimizer::metafile_path, &Optimizer::set_metafile_path)
442528
.def_property("tikhonov_parameter_rotation", &Optimizer::tikhonov_parameter_rotation, &Optimizer::set_tikhonov_parameter_rotation)
443529
.def_property("tikhonov_parameter_translation", &Optimizer::tikhonov_parameter_translation, &Optimizer::set_tikhonov_parameter_translation)
530+
.def_property_readonly("root_link", &Optimizer::root_link_ptr)
444531
;
445532

446533
// Constants

src/pym3t/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from ._pym3t_mod import Tracker
2+
from ._pym3t_mod import ColorHistograms
23
from ._pym3t_mod import RendererGeometry
34
from ._pym3t_mod import Intrinsics, IDType
45
from ._pym3t_mod import DummyColorCamera, DummyDepthCamera
@@ -7,14 +8,15 @@
78
from ._pym3t_mod import Body, Link
89
from ._pym3t_mod import StaticDetector
910
from ._pym3t_mod import RegionModel, DepthModel
10-
from ._pym3t_mod import RegionModality, DepthModality, TextureModality
11+
from ._pym3t_mod import RegionModality, DepthModality, TextureModality, DescriptorType
1112
from ._pym3t_mod import Optimizer
1213
from ._pym3t_mod import WITH_REALSENSE
1314

1415
if WITH_REALSENSE:
1516
from ._pym3t_mod import RealSenseColorCamera, RealSenseDepthCamera
1617

17-
__all__ = ['Tracker',
18+
__all__ = ['Tracker',
19+
'ColorHistograms',
1820
'RendererGeometry',
1921
'Intrinsics', 'IDType',
2022
'DummyColorCamera', 'DummyDepthCamera',
@@ -23,7 +25,7 @@
2325
'Body', 'Link',
2426
'StaticDetector',
2527
'RegionModel', 'DepthModel',
26-
'RegionModality', 'DepthModality', 'TextureModality'
28+
'RegionModality', 'DepthModality', 'TextureModality', 'DescriptorType'
2729
'Optimizer',]
2830

2931
if WITH_REALSENSE:

0 commit comments

Comments
 (0)