Monado OpenXR Runtime
t_frame_cv_mat_wrapper.hpp
Go to the documentation of this file.
1// Copyright 2021-2023, Collabora, Ltd.
2// SPDX-License-Identifier: BSL-1.0
3/*!
4 * @file
5 * @brief Simple @ref xrt_frame wrapper around a cv::Mat.
6 * @author Jakob Bornecrantz <jakob@collabora.com>
7 * @ingroup aux_tracking
8 */
9
10#include "xrt/xrt_frame.h"
11
12#include <opencv2/opencv.hpp>
13
14
15namespace xrt::auxiliary::tracking {
16
17
18/*!
19 * This class implements the @ref xrt_frame interface, allowing interfacing to
20 * @p cv::Mat from C code. Keeps a reference to the cv::Mat and so the data
21 * alive, this class is freed when the reference count reaches zero.
22 */
24{
25public:
26 //! Additional optional parameters for frame creation.
27 class Params
28 {
29 public:
30 enum xrt_stereo_format stereo_format;
31 uint64_t timestamp_ns;
32 };
33
34 //! Exposed @ref xrt_frame API.
35 struct xrt_frame frame = {};
36
37 // The cv::Mat that holds the data.
38 cv::Mat matrix = cv::Mat();
39
40
41public: // Methods
42 /*!
43 * Wraps the given cv::Mat assuming it's a 24bit RGB format matrix.
44 * In all but the most strange cases you probably want the pointer
45 * pointed to by @p xf_ptr to be `nullptr`, if not `nullptr` it will have
46 * its reference count decremented so make sure it's a valid pointer.
47 */
48 static void
49 wrapR8G8B8(const cv::Mat &mat, xrt_frame **fm_out, Params params = {});
50
51 /*!
52 * Wraps the given cv::Mat assuming it's a 8bit format matrix.
53 * In all but the most strange cases you probably want the pointer
54 * pointed to by @p xf_ptr to be `nullptr`, if not `nullptr` it will have
55 * its reference count decremented so make sure it's a valid pointer.
56 */
57 static void
58 wrapL8(const cv::Mat &mat, xrt_frame **fm_out, Params params = {});
59
60
61private:
62 ~FrameMat();
63 FrameMat();
64
65 void
66 fillInFields(cv::Mat mat, xrt_format format, const Params &params);
67
68 //! C callback used when the reference of the frames reaches zero.
69 static void
70 destroyFrame(xrt_frame *frame);
71};
72
73
74
75} // namespace xrt::auxiliary::tracking
Additional optional parameters for frame creation.
Definition: t_frame_cv_mat_wrapper.hpp:28
This class implements the xrt_frame interface, allowing interfacing to cv::Mat from C code.
Definition: t_frame_cv_mat_wrapper.hpp:24
static void wrapL8(const cv::Mat &mat, xrt_frame **fm_out, Params params={})
Wraps the given cv::Mat assuming it's a 8bit format matrix.
Definition: t_frame_cv_mat_wrapper.cpp:99
static void wrapR8G8B8(const cv::Mat &mat, xrt_frame **fm_out, Params params={})
Wraps the given cv::Mat assuming it's a 24bit RGB format matrix.
Definition: t_frame_cv_mat_wrapper.cpp:82
xrt_stereo_format
What type of stereo format a frame has.
Definition: xrt_defines.h:203
Definition: u_pacing_compositor.c:54
Basic frame data structure - holds a pointer to buffer.
Definition: xrt_frame.h:25
xrt_format
Common formats, use u_format_* functions to reason about them.
Definition: xrt_defines.h:176
Data frame header.