| 1 |
#include "colmap/geometry/triangulation.h" |
| 2 |
|
| 3 |
#include "colmap/util/logging.h" |
| 4 |
|
| 5 |
#include "pycolmap/helpers.h" |
| 6 |
#include "pycolmap/pybind11_extension.h" |
| 7 |
|
| 8 |
#include <pybind11/eigen.h> |
| 9 |
#include <pybind11/pybind11.h> |
| 10 |
#include <pybind11/stl.h> |
| 11 |
|
| 12 |
using namespace colmap; |
| 13 |
using namespace pybind11::literals; |
| 14 |
namespace py = pybind11; |
| 15 |
|
| 16 |
void BindTriangulation(py::module& m) { |
| 17 |
m.def( |
| 18 |
"triangulate_point", |
| 19 |
[](const Eigen::Matrix3x4d& cam1_from_world, |
| 20 |
const Eigen::Matrix3x4d& cam2_from_world, |
| 21 |
const Eigen::Vector2d& cam_point1, |
| 22 |
const Eigen::Vector2d& cam_point2) |
| 23 |
-> py::typing::Optional<Eigen::Vector3d> { |
| 24 |
Eigen::Vector3d point3D; |
| 25 |
if (TriangulatePoint(cam1_from_world, |
| 26 |
cam2_from_world, |
| 27 |
cam_point1, |
| 28 |
cam_point2, |
| 29 |
&point3D)) { |
| 30 |
return py::cast(point3D); |
| 31 |
} else { |
| 32 |
return py::none(); |
| 33 |
} |
| 34 |
}, |
| 35 |
"cam1_from_world"_a, |
| 36 |
"cam2_from_world"_a, |
| 37 |
"cam_point1"_a, |
| 38 |
"cam_point2"_a, |
| 39 |
"Triangulate point in world from two-view observation."); |
| 40 |
m.def( |
| 41 |
"triangulate_point", |
| 42 |
[](const Eigen::Matrix3x4d& cam1_from_world, |
| 43 |
const Eigen::Matrix3x4d& cam2_from_world, |
| 44 |
const Eigen::Vector3d& cam_ray1, |
| 45 |
const Eigen::Vector3d& cam_ray2) |
| 46 |
-> py::typing::Optional<Eigen::Vector3d> { |
| 47 |
Eigen::Vector3d point3D; |
| 48 |
if (TriangulatePoint(cam1_from_world, |
| 49 |
cam2_from_world, |
| 50 |
cam_ray1, |
| 51 |
cam_ray2, |
| 52 |
&point3D)) { |
| 53 |
return py::cast(point3D); |
| 54 |
} else { |
| 55 |
return py::none(); |
| 56 |
} |
| 57 |
}, |
| 58 |
"cam1_from_world"_a, |
| 59 |
"cam2_from_world"_a, |
| 60 |
"cam_ray1"_a, |
| 61 |
"cam_ray2"_a, |
| 62 |
"Triangulate point in world from two-view bearing-vector observation."); |
| 63 |
m.def( |
| 64 |
"triangulate_multi_view_point", |
| 65 |
[](const std::vector<Eigen::Matrix3x4d>& cams_from_world, |
| 66 |
const std::vector<Eigen::Vector3d>& cam_rays) |
| 67 |
-> py::typing::Optional<Eigen::Vector3d> { |
| 68 |
THROW_CHECK_EQ(cams_from_world.size(), cam_rays.size()); |
| 69 |
Eigen::Vector3d point3D; |
| 70 |
if (TriangulateMultiViewPoint( |
| 71 |
span<const Eigen::Matrix3x4d>(cams_from_world.data(), |
| 72 |
cams_from_world.size()), |
| 73 |
span<const Eigen::Vector3d>(cam_rays.data(), cam_rays.size()), |
| 74 |
&point3D)) { |
| 75 |
return py::cast(point3D); |
| 76 |
} else { |
| 77 |
return py::none(); |
| 78 |
} |
| 79 |
}, |
| 80 |
"cams_from_world"_a, |
| 81 |
"cam_rays"_a, |
| 82 |
"Triangulate point in world from multi-view bearing-vector " |
| 83 |
"observations."); |
| 84 |
m.def("calculate_triangulation_angle", |
| 85 |
&CalculateTriangulationAngle, |
| 86 |
"proj_center1"_a, |
| 87 |
"proj_center2"_a, |
| 88 |
"point3D"_a, |
| 89 |
"Calculate triangulation angle in radians."); |
| 90 |
|
| 91 |
m.def( |
| 92 |
"triangulate_mid_point", |
| 93 |
[](const Rigid3d& cam2_from_cam1, |
| 94 |
const Eigen::Vector3d& cam_ray1, |
| 95 |
const Eigen::Vector3d& cam_ray2) |
| 96 |
-> py::typing::Optional<Eigen::Vector3d> { |
| 97 |
Eigen::Vector3d point3D_in_cam1; |
| 98 |
if (TriangulateMidPoint( |
| 99 |
cam2_from_cam1, cam_ray1, cam_ray2, &point3D_in_cam1)) { |
| 100 |
return py::cast(point3D_in_cam1); |
| 101 |
} else { |
| 102 |
return py::none(); |
| 103 |
} |
| 104 |
}, |
| 105 |
"cam2_from_cam1"_a, |
| 106 |
"cam_ray1"_a, |
| 107 |
"cam_ray2"_a, |
| 108 |
"Triangulate mid-point in first camera from two-view observation."); |
| 109 |
} |