14 #ifdef BUILD_LIBREALSENSE
27 static const std::unordered_map<std::string, std::string>
29 {
"timestamp",
"Timestamp in the video (usec)."},
30 {
"filename",
"Path to the RGBD video file."},
32 "Frames will be stored in stream subfolders 'color' and "
33 "'depth' here. The intrinsic camera calibration for the "
34 "color stream will be saved in 'intrinsic.json'"},
36 "Start saving frames from this time (us)"},
38 "(default video length) Save frames till this time (us)"},
40 "Size of internal frame buffer, increase this if you "
41 "experience frame drops."}};
43 py::native_enum<SensorType>(m,
"SensorType",
"enum.Enum",
"Sensor type.")
49 py::class_<RGBDVideoMetadata> rgbd_video_metadata(m,
"RGBDVideoMetadata",
50 "RGBD Video metadata.");
51 rgbd_video_metadata.def(py::init<>())
53 "Shared intrinsics between RGB & depth")
55 "Capture device name")
57 "Capture device serial number")
58 .def_readwrite(
"stream_length_usec",
60 "Length of the video (usec). 0 for live capture.")
64 "Height of the video")
66 "Video frame rate (common for both color and depth)")
68 "Pixel format for color data")
70 "Pixel Dtype for color data.")
72 "Pixel format for depth data")
74 "Pixel Dtype for depth data.")
76 "Number of depth units per meter (depth in m = "
77 "depth_pixel_value/depth_scale).")
78 .def_readwrite(
"color_channels",
80 "Number of color channels.")
87 bool IsOpened()
const override {
91 bool IsEOF()
const override {
95 bool Open(
const std::string &
filename)
override {
99 void Close()
override {
112 bool SeekTimestamp(uint64_t timestamp)
override {
117 uint64_t GetTimestamp()
const override {
125 std::string GetFilename()
const override {
132 std::unique_ptr<RGBDVideoReader>>
133 rgbd_video_reader(m,
"RGBDVideoReader",
"RGBD Video file reader.");
134 rgbd_video_reader.def(py::init<>())
140 "filename"_a,
"Create RGBD video reader based on filename")
142 "start_time_us"_a = 0,
"end_time_us"_a = UINT64_MAX,
143 "Save synchronized and aligned individual frames to "
152 py::class_<RGBDSensor> rgbd_sensor(
153 m,
"RGBDSensor",
"Interface class for control of RGBD cameras.");
156 #ifdef BUILD_LIBREALSENSE
161 "RealSense Bag file reader.\n"
162 "\tOnly the first color and depth streams from the bag "
163 "file will be read.\n"
164 " - The streams must have the same frame rate.\n"
165 " - The color stream must have RGB 8 bit (RGB8/BGR8) pixel "
167 " - The depth stream must have 16 bit unsigned int (Z16) "
169 "The output is synchronized color and depth frame pairs "
170 "with the depth frame aligned to the color frame. "
171 "Unsynchronized frames will be dropped. With alignment, "
172 "the depth and color frames have the same viewpoint and "
173 "resolution. See format documentation `here "
174 "<https://intelrealsense.github.io/librealsense/doxygen/"
175 "rs__sensor_8h.html#ae04b7887ce35d16dbd9d2d295d23aac7>`__"
177 ".. warning:: A few frames may be dropped if user code "
178 "takes a long time (>10 frame intervals) to process a "
180 rs_bag_reader.def(py::init<>())
181 .def(py::init<size_t>(),
184 "Check if the RS bag file is opened.")
186 py::call_guard<py::gil_scoped_release>(),
"filename"_a,
187 "Open an RS bag playback.")
189 "Close the opened RS bag playback.")
191 "Check if the RS bag file is all read.")
196 "Get metadata of the RS bag playback.")
198 py::call_guard<py::gil_scoped_release>(),
"timestamp"_a,
199 "Seek to the timestamp (in us).")
201 "Get current timestamp (in us).")
203 py::call_guard<py::gil_scoped_release>(),
204 "Get next frame from the RS bag playback and returns the RGBD "
208 py::call_guard<py::gil_scoped_release>(),
"frame_path"_a,
209 "start_time_us"_a = 0,
"end_time_us"_a = UINT64_MAX,
210 "Save synchronized and aligned individual frames to "
223 py::class_<RealSenseSensorConfig> realsense_sensor_config(
224 m,
"RealSenseSensorConfig",
"Configuration for a RealSense camera");
226 realsense_sensor_config.def(py::init<>(),
"Default config will be used")
227 .def(py::init<
const std::unordered_map<std::string, std::string>
229 "config"_a,
"Initialize config with a map");
231 py::class_<RealSenseValidConfigs> realsense_valid_configs(
232 m,
"RealSenseValidConfigs",
233 "Store set of valid configuration options for a connected "
234 "RealSense device. From this structure, a user can construct a "
235 "RealSenseSensorConfig object meeting their specifications.");
236 realsense_valid_configs
238 "Device serial number.")
240 .def_readwrite(
"valid_configs",
242 "Mapping between configuraiton option name and a "
243 "list of valid values.");
246 py::class_<RealSenseSensor, RGBDSensor> realsense_sensor(
247 m,
"RealSenseSensor",
248 "RealSense camera discovery, configuration, streaming and "
250 realsense_sensor.def(py::init<>(),
"Initialize with default settings.")
252 py::call_guard<py::gil_scoped_release>(),
253 "List all RealSense cameras connected to the system "
254 "along with their capabilities. Use this listing to "
255 "select an appropriate configuration for a camera")
257 py::call_guard<py::gil_scoped_release>(),
258 "Query all connected RealSense cameras for their "
262 const std::string &>(
264 py::call_guard<py::gil_scoped_release>(),
266 "sensor_index"_a = 0,
"filename"_a =
"",
267 "Configure sensor with custom settings. If this is skipped, "
268 "default settings will be used. You can enable recording to a "
269 "bag file by specifying a filename.")
272 const std::string &>(
274 py::call_guard<py::gil_scoped_release>(),
276 "sensor_index"_a = 0,
"filename"_a =
"",
277 "Configure sensor with custom settings. If this is skipped, "
278 "default settings will be used. You can enable recording to a "
279 "bag file by specifying a filename.")
281 py::call_guard<py::gil_scoped_release>(),
282 "start_record"_a =
false,
283 "Start capturing synchronized depth and color frames.")
285 "Pause recording to the bag file. Note: If this is called "
286 "immediately after start_capture, the bag file may have an "
287 "incorrect end time.")
289 "Resume recording to the bag file. The file will contain "
290 "discontinuous segments.")
292 py::call_guard<py::gil_scoped_release>(),
"wait"_a =
true,
293 "align_depth_to_color"_a =
true,
294 "Acquire the next synchronized RGBD frameset from the camera.")
296 "Get current timestamp (in us)")
298 py::call_guard<py::gil_scoped_release>(),
299 "Stop capturing frames.")
301 "Get metadata of the RealSense video capture.")
303 "Get filename being written.")
307 m,
"RealSenseSensor",
"init_sensor",
309 "Camera configuration, such as resolution and framerate. A "
310 "serial number can be entered here to connect to a specific "
313 "Connect to a camera at this position in the enumeration of "
314 "RealSense cameras that are currently connected. Use "
315 "enumerate_devices() or list_devices() to obtain a list of "
316 "connected cameras. This is ignored if sensor_config contains "
318 {
"filename",
"Save frames to a bag file"}});
320 m,
"RealSenseSensor",
"start_capture",
322 "Start recording to the specified bag file as well."}});
324 m,
"RealSenseSensor",
"capture_frame",
326 "If true wait for the next frame set, else return immediately "
327 "with an empty RGBDImage if it is not yet available."},
328 {
"align_depth_to_color",
329 "Enable aligning WFOV depth image to the color image in "
RGBDImage A pair of color and depth images.
virtual const std::string ToString() const
Text Description.
static std::unique_ptr< RGBDVideoReader > Create(const std::string &filename)
Factory function to create object based on RGBD video file type.
virtual void SaveFrames(const std::string &frame_path, uint64_t start_time_us=0, uint64_t end_time_us=UINT64_MAX)
virtual std::string ToString() const
Text description.
virtual bool SeekTimestamp(uint64_t timestamp) override
static const size_t DEFAULT_BUFFER_SIZE
virtual bool IsEOF() const override
Check if the RSBag file is all read.
virtual void SaveFrames(const std::string &frame_path, uint64_t start_time_us=0, uint64_t end_time_us=UINT64_MAX)
virtual bool IsOpened() const override
Check If the RSBag file is opened.
virtual uint64_t GetTimestamp() const override
Get current timestamp (in us).
virtual bool Open(const std::string &filename) override
virtual t::geometry::RGBDImage NextFrame() override
Copy next frame from the bag file and return the RGBDImage object.
virtual const RGBDVideoMetadata & GetMetadata() const override
Get (read-only) metadata of the playback.
virtual std::string ToString() const
Text description.
virtual void Close() override
Close the opened RSBag playback.
virtual bool InitSensor(const RealSenseSensorConfig &sensor_config=RealSenseSensorConfig{}, size_t sensor_index=0, const std::string &filename="")
static bool ListDevices()
virtual std::string GetFilename() const override
Get filename being written.
virtual void StopCapture() override
Stop capturing frames.
static std::vector< RealSenseValidConfigs > EnumerateDevices()
virtual void PauseRecord() override
virtual uint64_t GetTimestamp() const override
virtual void ResumeRecord() override
virtual const RGBDVideoMetadata & GetMetadata() const override
Get metadata of the RealSense video capture.
virtual geometry::RGBDImage CaptureFrame(bool wait=true, bool align_depth_to_color=true) override
virtual bool StartCapture(bool start_record=false) override
virtual const std::string ToString() const
Text Description.
virtual std::string ToString() const
Convert to a styled string representation of JSON data for display.
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)
static const std::string path
void pybind_sensor(py::module &m)
static const std::unordered_map< std::string, std::string > map_shared_argument_docstrings
Generic file read and write utility for python interface.
std::unordered_map< std::string, std::set< std::string > > valid_configs
std::string serial
Device serial number.