5 #include "../include/librealsense2/rs.hpp" 8 py::class_<BufData> BufData_py(m,
"BufData", py::buffer_protocol());
9 BufData_py.def_buffer([](
BufData&
self)
10 {
return py::buffer_info(
22 if (
auto vf =
self.as<rs2::video_frame>()) {
24 switch (vf.get_profile().format()) {
26 return BufData(const_cast<void*>(vf.get_data()), 1, bytes_per_pixel_to_format[1], 3,
27 {
static_cast<size_t>(vf.get_height()), static_cast<size_t>(vf.get_width()), 3 },
28 {
static_cast<size_t>(vf.get_stride_in_bytes()), static_cast<size_t>(vf.get_bytes_per_pixel()), 1 });
31 return BufData(const_cast<void*>(vf.get_data()), 1, bytes_per_pixel_to_format[1], 3,
32 {
static_cast<size_t>(vf.get_height()), static_cast<size_t>(vf.get_width()), 4 },
33 {
static_cast<size_t>(vf.get_stride_in_bytes()), static_cast<size_t>(vf.get_bytes_per_pixel()), 1 });
36 return BufData(const_cast<void*>(vf.get_data()), static_cast<size_t>(vf.get_bytes_per_pixel()), bytes_per_pixel_to_format[vf.get_bytes_per_pixel()], 2,
37 {
static_cast<size_t>(vf.get_height()), static_cast<size_t>(vf.get_width()) },
38 {
static_cast<size_t>(vf.get_stride_in_bytes()), static_cast<size_t>(vf.get_bytes_per_pixel()) });
45 py::class_<rs2::stream_profile> stream_profile(m,
"stream_profile",
"Stores details about the profile of a stream.");
46 stream_profile.def(py::init<>())
52 .def(
"clone", &
rs2::stream_profile::clone,
"Clone the current profile and change the type, index and format to input parameters",
"type"_a,
"index"_a,
"format"_a)
58 "meaning that the profile will be selected when the user requests stream configuration using wildcards.")
59 .def(
"__nonzero__", &rs2::stream_profile::operator
bool,
"Checks if the profile is valid")
60 .def(
"__bool__", &rs2::stream_profile::operator
bool,
"Checks if the profile is valid")
64 "to a specific profile (sensor). The extrinsic information is generally available as part of the camera calibration, " 65 "and librealsense is responsible for retrieving and assigning these parameters where appropriate. This specific function " 66 "is intended for synthetic/mock-up (software) devices for which the parameters are produced and injected by the user.",
"to"_a,
"extrinsics"_a)
69 if (
auto vf =
self.as<rs2::video_stream_profile>())
71 ss <<
"<" SNAME ".video_stream_profile: " 72 << vf.stream_type() <<
"(" << vf.stream_index() <<
") " << vf.width()
73 <<
"x" << vf.height() <<
" @ " << vf.fps() <<
"fps " 74 << vf.format() <<
">";
78 ss <<
"<" SNAME ".stream_profile: " <<
self.stream_type() <<
"(" <<
self.stream_index()
79 <<
") @ " <<
self.fps() <<
"fps " <<
self.format() <<
">";
84 py::class_<rs2::video_stream_profile, rs2::stream_profile> video_stream_profile(m,
"video_stream_profile",
"Stream profile instance which contains additional video attributes.");
85 video_stream_profile.def(py::init<const rs2::stream_profile&>(),
"sp"_a)
92 ss <<
"<" SNAME ".video_stream_profile: " 93 <<
self.stream_type() <<
"(" <<
self.stream_index() <<
") " <<
self.width()
94 <<
"x" <<
self.height() <<
" @ " <<
self.fps() <<
"fps " 95 <<
self.format() <<
">";
99 py::class_<rs2::motion_stream_profile, rs2::stream_profile> motion_stream_profile(m,
"motion_stream_profile",
"Stream profile instance which contains IMU-specific intrinsics.");
100 motion_stream_profile.def(py::init<const rs2::stream_profile&>(),
"sp"_a)
103 py::class_<rs2::pose_stream_profile, rs2::stream_profile> pose_stream_profile(m,
"pose_stream_profile",
"Stream profile instance with an explicit pose extension type.");
104 pose_stream_profile.def(py::init<const rs2::stream_profile&>(),
"sp"_a);
106 py::class_<rs2::filter_interface> filter_interface(m,
"filter_interface",
"Interface for frame filtering functionality");
109 py::class_<rs2::frame> frame(m,
"frame",
"Base class for multiple frame extensions");
110 frame.def(py::init<>())
112 .def(py::init<rs2::frame>())
113 .def(
"swap", &
rs2::frame::swap,
"Swap the internal frame handle with the one in parameter",
"other"_a)
114 .def(
"__nonzero__", &rs2::frame::operator
bool,
"check if internal frame handle is valid")
115 .def(
"__bool__", &rs2::frame::operator
bool,
"check if internal frame handle is valid")
117 .def_property_readonly(
"timestamp", &
rs2::frame::get_timestamp,
"Time at which the frame was captured. Identical to calling get_timestamp.")
125 .def(
"get_data", get_frame_data,
"Retrieve data from the frame handle.", py::keep_alive<0, 1>())
126 .def_property_readonly(
"data", get_frame_data,
"Data from the frame handle. Identical to calling get_data.", py::keep_alive<0, 1>())
128 .def_property_readonly(
"profile", &
rs2::frame::get_profile,
"Stream profile from frame handle. Identical to calling get_profile.")
129 .def(
"keep", &
rs2::frame::keep,
"Keep the frame, otherwise if no refernce to the frame, the frame will be released.")
138 .def(
"__repr__", [](
const rs2::frame &
self )
140 std::stringstream ss;
141 ss <<
"<" <<
SNAME <<
".frame";
142 if(
auto fs =
self.as< rs2::frameset >() )
152 ss <<
" #" <<
self.get_frame_number();
157 py::class_<rs2::video_frame, rs2::frame> video_frame(m,
"video_frame",
"Extends the frame class with additional video related attributes and functions.");
158 video_frame.def(py::init<rs2::frame>())
164 .def_property_readonly(
"stride_in_bytes", &
rs2::video_frame::get_stride_in_bytes,
"Frame stride, meaning the actual line width in memory in bytes (not the logical image width). Identical to calling get_stride_in_bytes.")
171 std::vector<float> target_dims;
174 target_dims.resize(4);
178 },
"This will calculate the four target dimenson size(s) in millimeter on the specific target.");
180 py::class_<rs2::vertex>
vertex(m,
"vertex");
187 std::ostringstream oss;
188 oss << v.
x <<
", " << v.
y <<
", " << v.
z;
192 py::class_<rs2::texture_coordinate> texture_coordinate(m,
"texture_coordinate");
198 std::ostringstream oss;
199 oss << t.
u <<
", " << t.
v;
203 py::class_<rs2::points, rs2::frame>
points(m,
"points",
"Extends the frame class with additional point cloud related attributes and functions.");
204 points.def(py::init<>())
205 .def(py::init<rs2::frame>())
206 .def(
"get_vertices", [](
rs2::points&
self,
int dims) {
216 return BufData(
verts,
sizeof(
float),
"@f", 3, {
h,
w, 3 }, {
w*3*
sizeof(float), 3*
sizeof(
float),
sizeof(float) });
218 throw std::domain_error(
"dims arg only supports values of 1, 2 or 3");
220 },
"Retrieve the vertices of the point cloud", py::keep_alive<0, 1>(),
"dims"_a=1)
221 .def(
"get_texture_coordinates", [](
rs2::points&
self,
int dims) {
229 return BufData(tex,
sizeof(
float),
"@f", 2,
self.
size());
231 return BufData(tex,
sizeof(
float),
"@f", 2, {
h,
w, 2 }, {
w*2*
sizeof(float), 2*
sizeof(
float),
sizeof(float) });
233 throw std::domain_error(
"dims arg only supports values of 1, 2 or 3");
235 },
"Retrieve the texture coordinates (uv map) for the point cloud", py::keep_alive<0, 1>(),
"dims"_a=1)
239 py::class_<rs2::depth_frame, rs2::video_frame>
depth_frame(m,
"depth_frame",
"Extends the video_frame class with additional depth related attributes and functions.");
240 depth_frame.def(py::init<rs2::frame>())
242 .def(
"get_units", &
rs2::depth_frame::get_units,
"Provide the scaling factor to use when converting from get_data() units to meters");
245 py::class_<rs2::disparity_frame, rs2::depth_frame> disparity_frame(m,
"disparity_frame",
"Extends the depth_frame class with additional disparity related attributes and functions.");
246 disparity_frame.def(py::init<rs2::frame>())
249 py::class_<rs2::motion_frame, rs2::frame> motion_frame(m,
"motion_frame",
"Extends the frame class with additional motion related attributes and functions");
250 motion_frame.def(py::init<rs2::frame>())
254 py::class_<rs2::pose_frame, rs2::frame> pose_frame(m,
"pose_frame",
"Extends the frame class with additional pose related attributes and functions.");
255 pose_frame.def(py::init<rs2::frame>())
257 .def_property_readonly(
"pose_data", &
rs2::pose_frame::get_pose_data,
"Pose data from T2xx position tracking sensor. Identical to calling get_pose_data.");
260 py::class_<rs2::frameset, rs2::frame> frameset(m,
"composite_frame",
"Extends the frame class with additional frameset related attributes and functions");
261 frameset.def(py::init<rs2::frame>())
263 "If no frame is found, return an empty frame instance.",
"s"_a,
"f"_a =
RS2_FORMAT_ANY)
264 .def(
"first", &
rs2::frameset::first,
"Retrieve the first frame of a specific stream type and optionally with a specific format. " 265 "If no frame is found, an error will be thrown.",
"s"_a,
"f"_a =
RS2_FORMAT_ANY)
269 self.foreach_rs(callable);
270 },
"Extract internal frame handles from the frameset and invoke the action function",
"callable"_a)
271 .def(
"__getitem__", &rs2::frameset::operator[])
273 .def(
"get_color_frame", &
rs2::frameset::get_color_frame,
"Retrieve the first color frame, if no frame is found, search for the color frame from IR stream. " 274 "If one still can't be found, return an empty frame instance.")
276 "found, return an empty frame instance.",
"index"_a = 0)
280 return py::make_iterator(
self.
begin(),
self.
end());
281 }, py::keep_alive<0, 1>())
282 .def(
"__getitem__", [](
const rs2::frameset&
self, py::slice slice) {
284 if (!slice.compute(
self.size(), &
start, &
stop, &step, &slicelength))
285 throw py::error_already_set();
286 auto *flist =
new std::vector<rs2::frame>(slicelength);
287 for (
size_t i = 0;
i < slicelength; ++
i) {
288 (*flist)[
i] =
self[
start];
const char * rs2_format_to_string(rs2_format format)
rs2_motion_device_intrinsic get_motion_intrinsics() const
void register_extrinsics_to(const stream_profile &to, rs2_extrinsics extrinsics)
rs2_metadata_type get_frame_metadata(rs2_frame_metadata_value frame_metadata) const
rs2_extrinsics get_extrinsics_to(const stream_profile &to) const
stream_profile get_profile() const
rs2_calib_target_type
Calibration target type.
int get_bytes_per_pixel() const
#define BIND_DOWNCAST(class, downcast)
struct Vertex vertex[VERTEXNUM]
bool supports_frame_metadata(rs2_frame_metadata_value frame_metadata) const
void export_to_ply(const std::string &fname, video_frame texture)
std::string stream_name() const
GLdouble GLdouble GLdouble w
GLsizei const GLchar *const * string
GLfloat GLfloat GLfloat GLfloat h
static const textual_icon stop
rs2_pose get_pose_data() const
depth_frame get_depth_frame() const
frame first_or_default(rs2_stream s, rs2_format f=RS2_FORMAT_ANY) const
video_frame get_color_frame() const
void init_frame(py::module &m)
rs2_vector get_motion_data() const
frame first(rs2_stream s, rs2_format f=RS2_FORMAT_ANY) const
video_frame get_fisheye_frame(const size_t index=0) const
pose_frame get_pose_frame(const size_t index=0) const
double get_timestamp() const
float get_baseline(void) const
GLint GLint GLsizei GLint GLenum format
rs2_intrinsics get_intrinsics() const
rs2_format format() const
float get_distance(int x, int y) const
virtual rs2::frame process(rs2::frame frame) const =0
rs2_timestamp_domain get_frame_timestamp_domain() const
int get_bits_per_pixel() const
const int get_data_size() const
video_frame get_infrared_frame(const size_t index=0) const
unsigned long long get_frame_number() const
int get_stride_in_bytes() const
rs2_stream stream_type() const
stream_profile clone(rs2_stream type, int index, rs2_format format) const
GLdouble GLdouble GLint GLint const GLdouble * points