1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
|
// ----------------------------------------------------------------------------
// - Open3D: www.open3d.org -
// ----------------------------------------------------------------------------
// The MIT License (MIT)
//
// Copyright (c) 2018-2021 www.open3d.org
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
// ----------------------------------------------------------------------------
#include "open3d/geometry/RGBDImage.h"
#include "open3d/io/sensor/azure_kinect/AzureKinectRecorder.h"
#include "open3d/io/sensor/azure_kinect/AzureKinectSensor.h"
#include "open3d/io/sensor/azure_kinect/AzureKinectSensorConfig.h"
#include "open3d/io/sensor/azure_kinect/MKVReader.h"
#include "pybind/docstring.h"
#include "pybind/io/io.h"
namespace open3d {
namespace io {
void pybind_sensor(py::module &m) {
static const std::unordered_map<std::string, std::string>
map_shared_argument_docstrings = {
{"sensor_index", "The selected device index."},
{"config", "AzureKinectSensor's config file."},
{"timestamp", "Timestamp in the video (usec)."},
{"filename", "Path to the mkv file."},
{"enable_record", "Enable recording to mkv file."},
{"enable_align_depth_to_color",
"Enable aligning WFOV depth image to the color image in "
"visualizer."}};
// Class kinect config
py::class_<AzureKinectSensorConfig> azure_kinect_sensor_config(
m, "AzureKinectSensorConfig", "AzureKinect sensor configuration.");
py::detail::bind_default_constructor<AzureKinectSensorConfig>(
azure_kinect_sensor_config);
azure_kinect_sensor_config.def(
py::init([](const std::unordered_map<std::string, std::string>
&config) {
return new AzureKinectSensorConfig(config);
}),
"config"_a);
py::class_<MKVMetadata> azure_kinect_mkv_metadata(
m, "AzureKinectMKVMetadata", "AzureKinect mkv metadata.");
py::detail::bind_default_constructor<MKVMetadata>(
azure_kinect_mkv_metadata);
azure_kinect_mkv_metadata
.def_readwrite("width", &MKVMetadata::width_, "Width of the video")
.def_readwrite("height", &MKVMetadata::height_,
"Height of the video")
.def_readwrite("stream_length_usec",
&MKVMetadata::stream_length_usec_,
"Length of the video (usec)");
// Class sensor
py::class_<AzureKinectSensor> azure_kinect_sensor(m, "AzureKinectSensor",
"AzureKinect sensor.");
azure_kinect_sensor.def(
py::init([](const AzureKinectSensorConfig &sensor_config) {
return new AzureKinectSensor(sensor_config);
}),
"sensor_config"_a);
azure_kinect_sensor
.def("connect", &AzureKinectSensor::Connect, "sensor_index"_a,
"Connect to specified device.")
.def("disconnect", &AzureKinectSensor::Disconnect,
"Disconnect from the connected device.")
.def("capture_frame", &AzureKinectSensor::CaptureFrame,
"enable_align_depth_to_color"_a, "Capture an RGBD frame.")
.def_static("list_devices", &AzureKinectSensor::ListDevices,
"List available Azure Kinect devices");
docstring::ClassMethodDocInject(m, "AzureKinectSensor", "connect",
map_shared_argument_docstrings);
docstring::ClassMethodDocInject(m, "AzureKinectSensor", "capture_frame",
map_shared_argument_docstrings);
docstring::ClassMethodDocInject(m, "AzureKinectSensor", "list_devices",
map_shared_argument_docstrings);
// Class recorder
py::class_<AzureKinectRecorder> azure_kinect_recorder(
m, "AzureKinectRecorder", "AzureKinect recorder.");
azure_kinect_recorder.def(
py::init([](const AzureKinectSensorConfig &sensor_config,
size_t sensor_index) {
return new AzureKinectRecorder(sensor_config, sensor_index);
}),
"sensor_config"_a, "sensor_index"_a);
azure_kinect_recorder
.def("init_sensor", &AzureKinectRecorder::InitSensor,
"Initialize sensor.")
.def("is_record_created", &AzureKinectRecorder::IsRecordCreated,
"Check if the mkv file is created.")
.def("open_record", &AzureKinectRecorder::OpenRecord, "filename"_a,
"Attempt to create and open an mkv file.")
.def("close_record", &AzureKinectRecorder::CloseRecord,
"Close the recorded mkv file.")
.def("record_frame", &AzureKinectRecorder::RecordFrame,
"enable_record"_a, "enable_align_depth_to_color"_a,
"Record a frame to mkv if flag is on and return an RGBD "
"object.");
docstring::ClassMethodDocInject(m, "AzureKinectRecorder", "init_sensor",
map_shared_argument_docstrings);
docstring::ClassMethodDocInject(m, "AzureKinectRecorder",
"is_record_created",
map_shared_argument_docstrings);
docstring::ClassMethodDocInject(m, "AzureKinectRecorder", "open_record",
map_shared_argument_docstrings);
docstring::ClassMethodDocInject(m, "AzureKinectRecorder", "close_record",
map_shared_argument_docstrings);
docstring::ClassMethodDocInject(m, "AzureKinectRecorder", "record_frame",
map_shared_argument_docstrings);
// Class mkv reader
py::class_<MKVReader> azure_kinect_mkv_reader(
m, "AzureKinectMKVReader", "AzureKinect mkv file reader.");
azure_kinect_mkv_reader.def(py::init([]() { return MKVReader(); }));
azure_kinect_mkv_reader
.def("is_opened", &MKVReader::IsOpened,
"Check if the mkv file is opened.")
.def("open", &MKVReader::Open, "filename"_a,
"Open an mkv playback.")
.def("close", &MKVReader::Close, "Close the opened mkv playback.")
.def("is_eof", &MKVReader::IsEOF,
"Check if the mkv file is all read.")
.def("get_metadata", &MKVReader::GetMetadata,
"Get metadata of the mkv playback.")
.def("seek_timestamp", &MKVReader::SeekTimestamp, "timestamp"_a,
"Seek to the timestamp (in us).")
.def("next_frame", &MKVReader::NextFrame,
"Get next frame from the mkv playback and returns the RGBD "
"object.");
docstring::ClassMethodDocInject(m, "AzureKinectMKVReader", "open",
map_shared_argument_docstrings);
docstring::ClassMethodDocInject(m, "AzureKinectMKVReader", "close",
map_shared_argument_docstrings);
docstring::ClassMethodDocInject(m, "AzureKinectMKVReader", "is_eof",
map_shared_argument_docstrings);
docstring::ClassMethodDocInject(m, "AzureKinectMKVReader", "get_metadata",
map_shared_argument_docstrings);
docstring::ClassMethodDocInject(m, "AzureKinectMKVReader", "seek_timestamp",
map_shared_argument_docstrings);
docstring::ClassMethodDocInject(m, "AzureKinectMKVReader", "next_frame",
map_shared_argument_docstrings);
}
} // namespace io
} // namespace open3d
|