ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
sensor.cpp
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #include <RGBDImage.h>
9 
14 #include "pybind/docstring.h"
15 #include "pybind/io/io.h"
16 
17 namespace cloudViewer {
18 namespace io {
19 
20 void pybind_sensor(py::module &m) {
21  static const std::unordered_map<std::string, std::string>
23  {"sensor_index", "The selected device index."},
24  {"config", "AzureKinectSensor's config file."},
25  {"timestamp", "Timestamp in the video (usec)."},
26  {"filename", "Path to the mkv file."},
27  {"enable_record", "Enable recording to mkv file."},
28  {"enable_align_depth_to_color",
29  "Enable aligning WFOV depth image to the color image in "
30  "visualizer."}};
31 
32  // Class kinect config
33  py::class_<AzureKinectSensorConfig> azure_kinect_sensor_config(
34  m, "AzureKinectSensorConfig", "AzureKinect sensor configuration.");
35  py::detail::bind_default_constructor<AzureKinectSensorConfig>(
36  azure_kinect_sensor_config);
37  azure_kinect_sensor_config.def(
38  py::init([](const std::unordered_map<std::string, std::string>
39  &config) {
40  return new AzureKinectSensorConfig(config);
41  }),
42  "config"_a);
43 
44  py::class_<MKVMetadata> azure_kinect_mkv_metadata(
45  m, "AzureKinectMKVMetadata", "AzureKinect mkv metadata.");
46  py::detail::bind_default_constructor<MKVMetadata>(
47  azure_kinect_mkv_metadata);
48  azure_kinect_mkv_metadata
49  .def_readwrite("width", &MKVMetadata::width_, "Width of the video")
50  .def_readwrite("height", &MKVMetadata::height_,
51  "Height of the video")
52  .def_readwrite("stream_length_usec",
54  "Length of the video (usec)");
55 
56  // Class sensor
57  py::class_<AzureKinectSensor> azure_kinect_sensor(m, "AzureKinectSensor",
58  "AzureKinect sensor.");
59 
60  azure_kinect_sensor.def(
61  py::init([](const AzureKinectSensorConfig &sensor_config) {
62  return new AzureKinectSensor(sensor_config);
63  }),
64  "sensor_config"_a);
65  azure_kinect_sensor
66  .def("connect", &AzureKinectSensor::Connect, "sensor_index"_a,
67  "Connect to specified device.")
68  .def("disconnect", &AzureKinectSensor::Disconnect,
69  "Disconnect from the connected device.")
70  .def("capture_frame", &AzureKinectSensor::CaptureFrame,
71  "enable_align_depth_to_color"_a, "Capture an RGBD frame.")
72  .def_static("list_devices", &AzureKinectSensor::ListDevices,
73  "List available Azure Kinect devices");
74  docstring::ClassMethodDocInject(m, "AzureKinectSensor", "connect",
76  docstring::ClassMethodDocInject(m, "AzureKinectSensor", "capture_frame",
78  docstring::ClassMethodDocInject(m, "AzureKinectSensor", "list_devices",
80 
81  // Class recorder
82  py::class_<AzureKinectRecorder> azure_kinect_recorder(
83  m, "AzureKinectRecorder", "AzureKinect recorder.");
84 
85  azure_kinect_recorder.def(
86  py::init([](const AzureKinectSensorConfig &sensor_config,
87  size_t sensor_index) {
88  return new AzureKinectRecorder(sensor_config, sensor_index);
89  }),
90  "sensor_config"_a, "sensor_index"_a);
91  azure_kinect_recorder
92  .def("init_sensor", &AzureKinectRecorder::InitSensor,
93  "Initialize sensor.")
94  .def("is_record_created", &AzureKinectRecorder::IsRecordCreated,
95  "Check if the mkv file is created.")
96  .def("open_record", &AzureKinectRecorder::OpenRecord, "filename"_a,
97  "Attempt to create and open an mkv file.")
98  .def("close_record", &AzureKinectRecorder::CloseRecord,
99  "Close the recorded mkv file.")
100  .def("record_frame", &AzureKinectRecorder::RecordFrame,
101  "enable_record"_a, "enable_align_depth_to_color"_a,
102  "Record a frame to mkv if flag is on and return an RGBD "
103  "object.");
104  docstring::ClassMethodDocInject(m, "AzureKinectRecorder", "init_sensor",
106  docstring::ClassMethodDocInject(m, "AzureKinectRecorder",
107  "is_record_created",
109  docstring::ClassMethodDocInject(m, "AzureKinectRecorder", "open_record",
111  docstring::ClassMethodDocInject(m, "AzureKinectRecorder", "close_record",
113  docstring::ClassMethodDocInject(m, "AzureKinectRecorder", "record_frame",
115 
116  // Class mkv reader
117  py::class_<MKVReader> azure_kinect_mkv_reader(
118  m, "AzureKinectMKVReader", "AzureKinect mkv file reader.");
119  azure_kinect_mkv_reader.def(py::init([]() { return MKVReader(); }));
120  azure_kinect_mkv_reader
121  .def("is_opened", &MKVReader::IsOpened,
122  "Check if the mkv file is opened.")
123  .def("open", &MKVReader::Open, "filename"_a,
124  "Open an mkv playback.")
125  .def("close", &MKVReader::Close, "Close the opened mkv playback.")
126  .def("is_eof", &MKVReader::IsEOF,
127  "Check if the mkv file is all read.")
128  .def("get_metadata", &MKVReader::GetMetadata,
129  "Get metadata of the mkv playback.")
130  .def("seek_timestamp", &MKVReader::SeekTimestamp, "timestamp"_a,
131  "Seek to the timestamp (in us).")
132  .def("next_frame", &MKVReader::NextFrame,
133  "Get next frame from the mkv playback and returns the RGBD "
134  "object.");
135  docstring::ClassMethodDocInject(m, "AzureKinectMKVReader", "open",
137  docstring::ClassMethodDocInject(m, "AzureKinectMKVReader", "close",
139  docstring::ClassMethodDocInject(m, "AzureKinectMKVReader", "is_eof",
141  docstring::ClassMethodDocInject(m, "AzureKinectMKVReader", "get_metadata",
143  docstring::ClassMethodDocInject(m, "AzureKinectMKVReader", "seek_timestamp",
145  docstring::ClassMethodDocInject(m, "AzureKinectMKVReader", "next_frame",
147 }
148 
149 } // namespace io
150 } // namespace cloudViewer
bool IsRecordCreated()
Check if the mkv file is created.
bool InitSensor() override
Initialize sensor.
bool OpenRecord(const std::string &filename) override
bool CloseRecord() override
Close the recorded mkv file.
std::shared_ptr< geometry::RGBDImage > RecordFrame(bool write, bool enable_align_depth_to_color) override
static bool ListDevices()
List available Azure Kinect devices.
bool Connect(size_t sensor_index) override
std::shared_ptr< geometry::RGBDImage > CaptureFrame(bool enable_align_depth_to_color) const override
uint64_t stream_length_usec_
Length of the video (usec).
Definition: MKVMetadata.h:40
int width_
Width of the video.
Definition: MKVMetadata.h:42
int height_
Height of the video.
Definition: MKVMetadata.h:44
std::shared_ptr< geometry::RGBDImage > NextFrame()
Get next frame from the mkv playback and returns the RGBD object.
Definition: MKVReader.cpp:141
MKVMetadata & GetMetadata()
Get metadata of the mkv playback.
Definition: MKVReader.h:45
bool IsEOF()
Check if the mkv file is all read.
Definition: MKVReader.h:35
bool IsOpened()
Check If the mkv file is opened.
Definition: MKVReader.cpp:28
bool Open(const std::string &filename)
Definition: MKVReader.cpp:45
bool SeekTimestamp(size_t timestamp)
Seek to the timestamp (in us).
Definition: MKVReader.cpp:120
void Close()
Close the opened mkv playback.
Definition: MKVReader.cpp:62
void ClassMethodDocInject(py::module &pybind_module, const std::string &class_name, const std::string &function_name, const std::unordered_map< std::string, std::string > &map_parameter_body_docs)
Definition: docstring.cpp:27
static const std::unordered_map< std::string, std::string > map_shared_argument_docstrings
Definition: class_io.cpp:41
void pybind_sensor(py::module &m)
Definition: sensor.cpp:20
Generic file read and write utility for python interface.