25 #ifndef INCLUDED_ImagingInterface_h_GUID_E9CA5277_A0F5_488E_9E65_8541D437187C
26 #define INCLUDED_ImagingInterface_h_GUID_E9CA5277_A0F5_488E_9E65_8541D437187C
36 #include <opencv2/core/core.hpp>
51 class ImagingMessage {
62 std::size_t bytes = frame.total() * frame.elemSize();
65 std::memcpy(m_buf, frame.data, bytes);
66 m_frame = cv::Mat(frame.size(), frame.type(), m_buf);
74 cv::Mat
const &
getFrame()
const {
return m_frame; }
105 OSVR_ReturnCode ret =
108 throw std::logic_error(
"Could not initialize an Imaging "
109 "Interface with the device options "
119 throw std::logic_error(
120 "Must initialize the imaging interface before using it!");
122 cv::Mat
const &frame(message.getFrame());
124 util::opencvNumberTypeData(frame.type());
125 OSVR_ImagingMetadata metadata;
126 metadata.channels = frame.channels();
127 metadata.depth =
static_cast<OSVR_ImageDepth
>(typedata.getSize());
128 metadata.width = frame.cols;
129 metadata.height = frame.rows;
130 metadata.type = typedata.isFloatingPoint()
131 ? OSVR_IVT_FLOATING_POINT
132 : (typedata.isSigned() ? OSVR_IVT_SIGNED_INT
133 : OSVR_IVT_UNSIGNED_INT);
136 dev, m_iface, metadata, message.getBuf(), message.getSensor(),
139 throw std::runtime_error(
"Could not send imaging message!");
150 #endif // INCLUDED_ImagingInterface_h_GUID_E9CA5277_A0F5_488E_9E65_8541D437187C
uint32_t OSVR_ChannelCount
The integer type specifying a number of channels/sensors or a channel/sensor index.
Wrapper class for OSVR_DeviceToken.
Runtime data on numeric types.
ImagingInterface(OSVR_ImagingDeviceInterface iface=NULL)
Default constructor or constructor from an existing OSVR_ImagingDeviceInterface (assumed to be regist...
The main namespace for all C++ elements of the framework, internal and external.
A class wrapping a cv::Mat representing a frame, as well as the sensor ID it corresponds to...
typedefOSVR_EXTERN_C_BEGIN struct OSVR_ImagingDeviceInterfaceObject * OSVR_ImagingDeviceInterface
Opaque type used in conjunction with a device token to send data on an imaging interface.
ImagingInterface(OSVR_DeviceInitOptions opts, OSVR_ChannelCount numSensors=1)
Constructor that registers an imaging interface with the device init options object.
A class wrapping an imaging interface for a device.
struct OSVR_DeviceInitObject * OSVR_DeviceInitOptions
Opaque type of a device initialization object.
Header defining an aligned memory allocator.
#define OSVR_RETURN_SUCCESS
The "success" value for an OSVR_ReturnCode.
OSVR_ChannelCount getSensor() const
Gets the sensor number.
void send(DeviceToken &dev, ImagingMessage const &message, OSVR_TimeValue const ×tamp)
Send method - usually called by osvr::pluginkit::DeviceToken::send()
void * alignedAlloc(size_t bytes, size_t alignment=OSVR_DEFAULT_ALIGN_SIZE)
Aligned allocation function, gives a pointer to a block of memory aligned to a memory boundary...
OSVR_ImageBufferElement * getBuf() const
Retrieves the (cloned) buffer pointer.
OSVR_ReturnCode osvrDeviceImagingConfigure(OSVR_DeviceInitOptions opts, OSVR_ImagingDeviceInterface *iface, OSVR_ChannelCount numSensors=1)
Specify that your device will implement the Imaging interface.
Standardized, portable parallel to struct timeval for representing both absolute times and time inter...
unsigned char OSVR_ImageBufferElement
Type for raw buffer access to image data.
OSVR_ReturnCode osvrDeviceImagingReportFrame(OSVR_DeviceToken dev, OSVR_ImagingDeviceInterface iface, OSVR_ImagingMetadata metadata, OSVR_ImageBufferElement *imageData, OSVR_ChannelCount sensor, OSVR_TimeValue const *timestamp)
Report a frame for a sensor. Takes ownership of the buffer and frees it with the osvrAlignedFree func...
void alignedFree(void *p)
Aligned deallocation function, uses the pointer to the original memory block to deallocate it...
cv::Mat const & getFrame() const
Retrieves a reference to the cv::Mat object.
Header providing C++ interface wrappers around functionality in DeviceInterfaceC.h.
ImagingMessage(cv::Mat const &frame, OSVR_ChannelCount sensor=0)
Constructor, optionally taking a sensor number. Clones the supplied image/data as the imaging interfa...