-
Notifications
You must be signed in to change notification settings - Fork 3
How to use
To make OpenNI support this virtual device, you just need to put the "VirtualDevice.dll" file into the OpenNI driver directory.
The drivers usally at the path "OpenNI2\Drivers" relate to working directory. (You should find files like PS1080.dll, Kinect.dll inside this directory).
After copy the file into drivers directory, you can crate a virtual device with URI:
\\OpenNI2\\VirtualDevice\\<<STRING>>
The term <<STRING>> could be replaced with other string.
Here is an example:
Device devVirDevice;
devVirDevice.open( "\\OpenNI2\\VirtualDevice\\TEST" );
After virtual device created successfully, you can crate the depth and color VideoStream of it. You MUST set the VideoMode for each VideoStream you created.
If you are using a VideoStream for depth map, the properties ONI_STREAM_PROPERTY_VERTICAL_FOV and ONI_STREAM_PROPERTY_HORIZONTAL_FOV are required for coordinate convert (between depth and world).
It is recommand to use another thread to assign the images to the VideoStream of virtual device.
To assign a new map to the virtual device, you need to request a new frame object form the VideoStream, with the the function invoke():
OniFrame* pFrame = NULL;
devVirDevice.invoke( GET_VIRTUAL_STREAM_IMAGE, pFrame );
then you can modify the map in the form OniFrame.
After the data of frame is ok, use command
devVirDevice.invoke( SET_VIRTUAL_STREAM_IMAGE, pFrame );
to make the VideoStream know it get a new frame.
The special command GET_VIRTUAL_STREAM_IMAGE and SET_VIRTUAL_STREAM_IMAGE is defined in the file VirtualDevice.h.
https://github.com/VIML/VirtualDeviceForOpenNI2/blob/master/VirtualDevice/VirtualDevice.h
Here is an small example to set new data
// get a frame form virtual video stream
OniFrame* pFrame = NULL;
if( devVirDevice.invoke( GET_VIRTUAL_STREAM_IMAGE, pFrame ) == openni::STATUS_OK )
{
// type casting
DepthPixel* pVirData = reinterpret_cast<DepthPixel*>( pFrame->data );
// Fill dummy data
for( int y = 0; y < pFrame->height; ++ y )
{
for( int x = 0; x < pFrame->width; ++ x )
{
int idx = x + y * pFrame->width;
pVirData[idx] = 100;
}
}
// write data to form virtual video stream
devVirDevice.invoke( SET_VIRTUAL_STREAM_IMAGE, pFrame );
}
This virtual device provide a pool to store any type of properties. User can assign any type of property, the virtual device will make a copy of the data.
Most of property will just save in the device, and make no affect.
For example, you can set the property ONI_STREAM_PROPERTY_MIRRORING to the VideoStream, but it will NOT make the image mirror.
Only ONI_STREAM_PROPERTY_VIDEO_MODE and ONI_STREAM_PROPERTY_CROPPING will affect the device.
Here is a basic usage example: https://github.com/VIML/VirtualDeviceForOpenNI2/blob/master/Samples/BasicSample/main.cpp
If you want to use with an existed OpenNI Device, please see the sample https://github.com/VIML/VirtualDeviceForOpenNI2/blob/master/Samples/ExistedDeviceSample/main.cpp