1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
|
// ----------------------------------------------------------------------------
// - Open3D: www.open3d.org -
// ----------------------------------------------------------------------------
// The MIT License (MIT)
//
// Copyright (c) 2018-2021 www.open3d.org
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
// ----------------------------------------------------------------------------
#include "open3d/pipelines/odometry/Odometry.h"
#include "open3d/geometry/Image.h"
#include "open3d/geometry/RGBDImage.h"
#include "open3d/pipelines/odometry/OdometryOption.h"
#include "open3d/pipelines/odometry/RGBDOdometryJacobian.h"
#include "pybind/docstring.h"
#include "pybind/pipelines/odometry/odometry.h"
namespace open3d {
namespace pipelines {
namespace odometry {
template <class RGBDOdometryJacobianBase = RGBDOdometryJacobian>
class PyRGBDOdometryJacobian : public RGBDOdometryJacobianBase {
public:
using RGBDOdometryJacobianBase::RGBDOdometryJacobianBase;
void ComputeJacobianAndResidual(
int row,
std::vector<Eigen::Vector6d, utility::Vector6d_allocator> &J_r,
std::vector<double> &r,
std::vector<double> &w,
const geometry::RGBDImage &source,
const geometry::RGBDImage &target,
const geometry::Image &source_xyz,
const geometry::RGBDImage &target_dx,
const geometry::RGBDImage &target_dy,
const Eigen::Matrix3d &intrinsic,
const Eigen::Matrix4d &extrinsic,
const CorrespondenceSetPixelWise &corresps) const override {
PYBIND11_OVERLOAD_PURE(void, RGBDOdometryJacobianBase, row, J_r, r,
source, target, source_xyz, target_dx, target_dy,
extrinsic, corresps, intrinsic);
}
};
void pybind_odometry_classes(py::module &m) {
// open3d.odometry.OdometryOption
py::class_<OdometryOption> odometry_option(
m, "OdometryOption", "Class that defines Odometry options.");
odometry_option
.def(py::init(
[](std::vector<int> iteration_number_per_pyramid_level,
double depth_diff_max, double depth_min,
double depth_max) {
return new OdometryOption(
iteration_number_per_pyramid_level,
depth_diff_max, depth_min, depth_max);
}),
"iteration_number_per_pyramid_level"_a =
std::vector<int>{20, 10, 5},
"depth_diff_max"_a = 0.03, "depth_min"_a = 0.0,
"depth_max"_a = 4.0)
.def_readwrite("iteration_number_per_pyramid_level",
&OdometryOption::iteration_number_per_pyramid_level_,
"List(int): Iteration number per image pyramid "
"level, typically larger image in the pyramid have "
"lower iteration number to reduce computation "
"time.")
.def_readwrite("depth_diff_max", &OdometryOption::depth_diff_max_,
"Maximum depth difference to be considered as "
"correspondence. In depth image domain, if two "
"aligned pixels have a depth difference less than "
"specified value, they are considered as a "
"correspondence. Larger value induce more "
"aggressive search, but it is prone to unstable "
"result.")
.def_readwrite("depth_min", &OdometryOption::depth_min_,
"Pixels that has smaller than specified depth "
"values are ignored.")
.def_readwrite("depth_max", &OdometryOption::depth_max_,
"Pixels that has larger than specified depth values "
"are ignored.")
.def("__repr__", [](const OdometryOption &c) {
int num_pyramid_level =
(int)c.iteration_number_per_pyramid_level_.size();
std::string str_iteration_number_per_pyramid_level_ = "[ ";
for (int i = 0; i < num_pyramid_level; i++)
str_iteration_number_per_pyramid_level_ +=
std::to_string(
c.iteration_number_per_pyramid_level_[i]) +
", ";
str_iteration_number_per_pyramid_level_ += "] ";
return std::string("OdometryOption class.") +
/*std::string("\nodo_init = ") +
std::to_string(c.odo_init_) +*/
std::string("\niteration_number_per_pyramid_level = ") +
str_iteration_number_per_pyramid_level_ +
std::string("\ndepth_diff_max = ") +
std::to_string(c.depth_diff_max_) +
std::string("\ndepth_min = ") +
std::to_string(c.depth_min_) +
std::string("\ndepth_max = ") +
std::to_string(c.depth_max_);
});
// open3d.odometry.RGBDOdometryJacobian
py::class_<RGBDOdometryJacobian,
PyRGBDOdometryJacobian<RGBDOdometryJacobian>>
jacobian(
m, "RGBDOdometryJacobian",
"Base class that computes Jacobian from two RGB-D images.");
// open3d.odometry.RGBDOdometryJacobianFromColorTerm: RGBDOdometryJacobian
py::class_<RGBDOdometryJacobianFromColorTerm,
PyRGBDOdometryJacobian<RGBDOdometryJacobianFromColorTerm>,
RGBDOdometryJacobian>
jacobian_color(m, "RGBDOdometryJacobianFromColorTerm",
R"(Class to Compute Jacobian using color term.
Energy: :math:`(I_p-I_q)^2.`
Reference:
F. Steinbrucker, J. Sturm, and D. Cremers.
Real-time visual odometry from dense RGB-D images.
In ICCV Workshops, 2011.)");
py::detail::bind_default_constructor<RGBDOdometryJacobianFromColorTerm>(
jacobian_color);
py::detail::bind_copy_functions<RGBDOdometryJacobianFromColorTerm>(
jacobian_color);
jacobian_color.def(
"__repr__", [](const RGBDOdometryJacobianFromColorTerm &te) {
return std::string("RGBDOdometryJacobianFromColorTerm");
});
// open3d.odometry.RGBDOdometryJacobianFromHybridTerm: RGBDOdometryJacobian
py::class_<RGBDOdometryJacobianFromHybridTerm,
PyRGBDOdometryJacobian<RGBDOdometryJacobianFromHybridTerm>,
RGBDOdometryJacobian>
jacobian_hybrid(m, "RGBDOdometryJacobianFromHybridTerm",
R"(Class to compute Jacobian using hybrid term
Energy: :math:`(I_p-I_q)^2 + \lambda(D_p-D_q')^2`
Reference:
J. Park, Q.-Y. Zhou, and V. Koltun
Anonymous submission.)");
py::detail::bind_default_constructor<RGBDOdometryJacobianFromHybridTerm>(
jacobian_hybrid);
py::detail::bind_copy_functions<RGBDOdometryJacobianFromHybridTerm>(
jacobian_hybrid);
jacobian_hybrid.def(
"__repr__", [](const RGBDOdometryJacobianFromHybridTerm &te) {
return std::string("RGBDOdometryJacobianFromHybridTerm");
});
}
void pybind_odometry_methods(py::module &m) {
m.def("compute_rgbd_odometry", &ComputeRGBDOdometry,
py::call_guard<py::gil_scoped_release>(),
"Function to estimate 6D rigid motion from two RGBD image pairs. "
"Output: (is_success, 4x4 motion matrix, 6x6 information matrix).",
"rgbd_source"_a, "rgbd_target"_a,
"pinhole_camera_intrinsic"_a = camera::PinholeCameraIntrinsic(),
"odo_init"_a = Eigen::Matrix4d::Identity(),
"jacobian"_a = RGBDOdometryJacobianFromHybridTerm(),
"option"_a = OdometryOption());
docstring::FunctionDocInject(
m, "compute_rgbd_odometry",
{
{"rgbd_source", "Source RGBD image."},
{"rgbd_target", "Target RGBD image."},
{"pinhole_camera_intrinsic", "Camera intrinsic parameters"},
{"odo_init", "Initial 4x4 motion matrix estimation."},
{"jacobian",
"The odometry Jacobian method to use. Can be "
"``"
"RGBDOdometryJacobianFromHybridTerm()`` or "
"``RGBDOdometryJacobianFromColorTerm("
").``"},
{"option", "Odometry hyper parameters."},
});
}
void pybind_odometry(py::module &m) {
py::module m_submodule = m.def_submodule("odometry", "Odometry pipeline.");
pybind_odometry_classes(m_submodule);
pybind_odometry_methods(m_submodule);
}
} // namespace odometry
} // namespace pipelines
} // namespace open3d
|