pyrsutil.cpp
Go to the documentation of this file.
1 /* License: Apache 2.0. See LICENSE file in root directory.
2 Copyright(c) 2017 Intel Corporation. All Rights Reserved. */
3 
4 #include "python.hpp"
5 #include "../include/librealsense2/rsutil.h"
6 
7 void init_util(py::module &m) {
9  m.def("rs2_project_point_to_pixel", [](const rs2_intrinsics& intrin, const std::array<float, 3>& point)->std::array<float, 2>
10  {
11  std::array<float, 2> pixel{};
12  rs2_project_point_to_pixel(pixel.data(), &intrin, point.data());
13  return pixel;
14  }, "Given a point in 3D space, compute the corresponding pixel coordinates in an image with no distortion or forward distortion coefficients produced by the same camera",
15  "intrin"_a, "point"_a);
16 
17  m.def("rs2_deproject_pixel_to_point", [](const rs2_intrinsics& intrin, const std::array<float, 2>& pixel, float depth)->std::array<float, 3>
18  {
19  std::array<float, 3> point{};
20  rs2_deproject_pixel_to_point(point.data(), &intrin, pixel.data(), depth);
21  return point;
22  }, "Given pixel coordinates and depth in an image with no distortion or inverse distortion coefficients, compute the corresponding point in 3D space relative to the same camera",
23  "intrin"_a, "pixel"_a, "depth"_a);
24 
25  m.def("rs2_transform_point_to_point", [](const rs2_extrinsics& extrin, const std::array<float, 3>& from_point)->std::array<float, 3>
26  {
27  std::array<float, 3> to_point{};
28  rs2_transform_point_to_point(to_point.data(), &extrin, from_point.data());
29  return to_point;
30  }, "Transform 3D coordinates relative to one sensor to 3D coordinates relative to another viewpoint",
31  "extrin"_a, "from_point"_a);
32 
33  m.def("rs2_fov", [](const rs2_intrinsics& intrin)->std::array<float, 2>
34  {
35  std::array<float, 2> to_fow{};
36  rs2_fov(&intrin, to_fow.data());
37  return to_fow;
38  }, "Calculate horizontal and vertical field of view, based on video intrinsics", "intrin"_a);
39 
40  m.def("next_pixel_in_line", [](std::array<float, 2> curr, const std::array<float, 2> start, const std::array<float, 2> end)->std::array<float, 2>
41  {
42  next_pixel_in_line(curr.data(), start.data(), end.data());
43  return curr;
44  }, "curr"_a, "start"_a, "end"_a);
45 
46  m.def("is_pixel_in_line", [](std::array<float, 2> curr, const std::array<float, 2> start, const std::array<float, 2> end)->bool
47  {
48  return is_pixel_in_line(curr.data(), start.data(), end.data());
49  }, "curr"_a, "start"_a, "end"_a); // Wrapping needed because raw arrays
50 
51  m.def("adjust_2D_point_to_boundary", [](std::array<float, 2> p, int width, int height)->std::array<float, 2>
52  {
54  return p;
55  }, "p"_a, "width"_a, "height"_a);
56 
57  auto cp_to_dp = [](BufData data, float depth_scale, float depth_min, float depth_max,
58  const rs2_intrinsics& depth_intrin, const rs2_intrinsics& color_intrin,
59  const rs2_extrinsics& color_to_depth, const rs2_extrinsics& depth_to_color,
60  std::array<float, 2> from_pixel)->std::array<float, 2>
61  {
62  std::array<float, 2> to_pixel;
63  rs2_project_color_pixel_to_depth_pixel(to_pixel.data(), static_cast<const uint16_t*>(data._ptr),
64  depth_scale, depth_min, depth_max, &depth_intrin, &color_intrin, &depth_to_color,
65  &color_to_depth, from_pixel.data());
66  return to_pixel;
67  };
68 
69  m.def("rs2_project_color_pixel_to_depth_pixel", cp_to_dp, "data"_a, "depth_scale"_a,
70  "depth_min"_a, "depth_max"_a, "depth_intrin"_a, "color_intrin"_a, "depth_to_color"_a,
71  "color_to_depth"_a, "from_pixel"_a);
73 }
static void rs2_transform_point_to_point(float to_point[3], const struct rs2_extrinsics *extrin, const float from_point[3])
Definition: rsutil.h:168
GLuint GLuint end
GLfloat GLfloat p
Definition: glext.h:12687
const GLfloat * m
Definition: glext.h:6814
static void rs2_fov(const struct rs2_intrinsics *intrin, float to_fov[2])
Definition: rsutil.h:176
rs2_intrinsics intrin
GLint GLint GLsizei GLsizei GLsizei depth
unsigned short uint16_t
Definition: stdint.h:79
void init_util(py::module &m)
Definition: pyrsutil.cpp:7
point
Definition: rmse.py:166
static void rs2_deproject_pixel_to_point(float point[3], const struct rs2_intrinsics *intrin, const float pixel[2], float depth)
Definition: rsutil.h:83
static void adjust_2D_point_to_boundary(float p[2], int width, int height)
Definition: rsutil.h:203
void * _ptr
Definition: python.hpp:199
GLint GLsizei GLsizei height
GLuint start
static void next_pixel_in_line(float curr[2], const float start[2], const float end[2])
Definition: rsutil.h:182
Cross-stream extrinsics: encodes the topology describing how the different devices are oriented...
Definition: rs_sensor.h:96
static void rs2_project_point_to_pixel(float pixel[2], const struct rs2_intrinsics *intrin, const float point[3])
Definition: rsutil.h:19
static bool is_pixel_in_line(const float curr[2], const float start[2], const float end[2])
Definition: rsutil.h:197
std::pair< int, int > pixel
Definition: rs-measure.cpp:18
Video stream intrinsics.
Definition: rs_types.h:58
static void rs2_project_color_pixel_to_depth_pixel(float to_pixel[2], const uint16_t *data, float depth_scale, float depth_min, float depth_max, const struct rs2_intrinsics *depth_intrin, const struct rs2_intrinsics *color_intrin, const struct rs2_extrinsics *color_to_depth, const struct rs2_extrinsics *depth_to_color, const float from_pixel[2])
Definition: rsutil.h:212
GLboolean * data
GLint GLsizei width


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:47:39