| 1 |
#include "colmap/image/undistortion.h" |
| 2 |
|
| 3 |
#include "pycolmap/helpers.h" |
| 4 |
#include "pycolmap/pybind11_extension.h" |
| 5 |
|
| 6 |
#include <pybind11/eigen.h> |
| 7 |
#include <pybind11/pybind11.h> |
| 8 |
|
| 9 |
using namespace colmap; |
| 10 |
using namespace pybind11::literals; |
| 11 |
namespace py = pybind11; |
| 12 |
|
| 13 |
void BindUndistortion(py::module& m) { |
| 14 |
auto PyWarpImageOptions = |
| 15 |
py::classh<WarpImageOptions>(m, "WarpImageOptions").def(py::init<>()); |
| 16 |
auto PyInterpolation = |
| 17 |
py::enum_<WarpImageOptions::Interpolation>(PyWarpImageOptions, |
| 18 |
"Interpolation") |
| 19 |
.value("NEAREST_NEIGHBOR", |
| 20 |
WarpImageOptions::Interpolation::kNearestNeighbor) |
| 21 |
.value("BILINEAR", WarpImageOptions::Interpolation::kBilinear); |
| 22 |
AddStringToEnumConstructor(PyInterpolation); |
| 23 |
PyWarpImageOptions |
| 24 |
.def_readwrite("interpolation", &WarpImageOptions::interpolation) |
| 25 |
.def_readwrite("direct_warp_min_scale", |
| 26 |
&WarpImageOptions::direct_warp_min_scale); |
| 27 |
MakeDataclass(PyWarpImageOptions); |
| 28 |
|
| 29 |
auto PyUndistortCameraOptions = |
| 30 |
py::classh<UndistortCameraOptions>(m, "UndistortCameraOptions") |
| 31 |
.def(py::init<>()) |
| 32 |
.def_readwrite("blank_pixels", &UndistortCameraOptions::blank_pixels) |
| 33 |
.def_readwrite("min_scale", &UndistortCameraOptions::min_scale) |
| 34 |
.def_readwrite("max_scale", &UndistortCameraOptions::max_scale) |
| 35 |
.def_readwrite("max_image_size", |
| 36 |
&UndistortCameraOptions::max_image_size) |
| 37 |
.def_readwrite("roi_min_x", &UndistortCameraOptions::roi_min_x) |
| 38 |
.def_readwrite("roi_min_y", &UndistortCameraOptions::roi_min_y) |
| 39 |
.def_readwrite("roi_max_x", &UndistortCameraOptions::roi_max_x) |
| 40 |
.def_readwrite("roi_max_y", &UndistortCameraOptions::roi_max_y) |
| 41 |
.def_readwrite("max_cam_point_norm", |
| 42 |
&UndistortCameraOptions::max_cam_point_norm) |
| 43 |
.def_readwrite("warp_options", &UndistortCameraOptions::warp_options); |
| 44 |
MakeDataclass(PyUndistortCameraOptions); |
| 45 |
|
| 46 |
m.def("undistort_camera", |
| 47 |
&UndistortCamera, |
| 48 |
"options"_a, |
| 49 |
"camera"_a, |
| 50 |
"Undistort camera."); |
| 51 |
|
| 52 |
m.def( |
| 53 |
"undistort_image", |
| 54 |
[](const UndistortCameraOptions& options, |
| 55 |
const Bitmap& distorted_image, |
| 56 |
const Camera& distorted_camera) -> std::pair<Bitmap, Camera> { |
| 57 |
py::gil_scoped_release release; |
| 58 |
std::pair<Bitmap, Camera> result; |
| 59 |
UndistortImage(options, |
| 60 |
distorted_image, |
| 61 |
distorted_camera, |
| 62 |
&result.first, |
| 63 |
&result.second); |
| 64 |
return result; |
| 65 |
}, |
| 66 |
"options"_a, |
| 67 |
"distorted_image"_a, |
| 68 |
"distorted_camera"_a, |
| 69 |
"Undistort image and corresponding camera."); |
| 70 |
} |