MCPcopy Create free account
hub / github.com/OSVR/OSVR-Core / ImagingInterface

Class ImagingInterface

inc/osvr/PluginKit/ImagingInterface.h:76–128  ·  view source on GitHub ↗

@brief A class wrapping an imaging interface for a device.

Source from the content-addressed store, hash-verified

74
75 /// @brief A class wrapping an imaging interface for a device.
76 class ImagingInterface {
77 public:
78 /// @brief Default constructor or constructor from an existing
79 /// OSVR_ImagingDeviceInterface (assumed to be registered with an
80 /// OSVR_DeviceInitOptions already)
81 ImagingInterface(OSVR_ImagingDeviceInterface iface = NULL)
82 : m_iface(iface) {}
83
84 /// @brief Constructor that registers an imaging interface with the
85 /// device init options object.
86 explicit ImagingInterface(OSVR_DeviceInitOptions opts,
87 OSVR_ChannelCount numSensors = 1) {
88 OSVR_ReturnCode ret =
89 osvrDeviceImagingConfigure(opts, &m_iface, numSensors);
90 if (OSVR_RETURN_SUCCESS != ret) {
91 throw std::logic_error("Could not initialize an Imaging "
92 "Interface with the device options "
93 "given!");
94 }
95 }
96
97 /// @brief Send method - usually called by
98 /// osvr::pluginkit::DeviceToken::send()
99 void send(DeviceToken &dev, ImagingMessage const &message,
100 OSVR_TimeValue const &timestamp) {
101 if (!m_iface) {
102 throw std::logic_error(
103 "Must initialize the imaging interface before using it!");
104 }
105 cv::Mat const &frame(message.getFrame());
106 util::NumberTypeData typedata =
107 util::opencvNumberTypeData(frame.type());
108 OSVR_ImagingMetadata metadata;
109 metadata.channels = frame.channels();
110 metadata.depth = typedata.getSize();
111 metadata.width = frame.cols;
112 metadata.height = frame.rows;
113 metadata.type = typedata.isFloatingPoint()
114 ? OSVR_IVT_FLOATING_POINT
115 : (typedata.isSigned() ? OSVR_IVT_SIGNED_INT
116 : OSVR_IVT_UNSIGNED_INT);
117
118 OSVR_ReturnCode ret =
119 osvrDeviceImagingReportFrame(dev, m_iface, metadata, frame.data,
120 message.getSensor(), &timestamp);
121 if (OSVR_RETURN_SUCCESS != ret) {
122 throw std::runtime_error("Could not send imaging message!");
123 }
124 }
125
126 private:
127 OSVR_ImagingDeviceInterface m_iface;
128 };
129 /// @}
130} // namespace pluginkit
131} // namespace osvr

Callers 1

CameraDeviceMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected