How to get OpenCV (EmguCV) Image from Primesense Kinect RGB camera
Previous article shows how to construct OpenCV Image from data comming from Kinect Depth camera using Primesense drivers. This article shows the same for Kinect RGB camera. Instead of constructing Image
Solution
The code takes RGB map from _rgbGenerator (OpenNI.ImageGenerator) and calculates RGB image (new Image<Bgr, Byte>(width, height)). Code presented uses unsafe sequences and array pointers to maximize the speed (you need to set up compiler with unsafe option).
Working C# code sample
This code is part of TouchTable project.
private unsafe void processDepthFrame()
{
var depthMd = new DepthMetaData();
// process pDepth
_depthGenerator.GetMetaData(depthMd);
var pDepth = (ushort*)_depthGenerator.DepthMapPtr.ToPointer();
ushort* pCurrentDepth = pDepth;
var width = depthMd.XRes;
var height = depthMd.YRes;
depthImage = new Image<Gray, Byte>(width, height);
var data = depthImage.Data;
var minimalFingerHeight = Config.MinimalFingerHeight;
fixed (int* pEnvDistances = _envDistances)
{
fixed (int* pTableDistances = TableDistancesYX)
{
fixed (byte* pImageData = data)
{
var pCurrEnvDistance = pEnvDistances;
var pCurrTableDistance = pTableDistances;
var pCurrImageData = pImageData;
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++, pCurrentDepth += 1, pCurrEnvDistance++, pCurrTableDistance++, pCurrImageData++)
{
var distFromKinect = *pCurrentDepth;
// Remember values
if (saveEnvDistances)
{
*pCurrEnvDistance = distFromKinect;
}
int distFromTable = (*pCurrEnvDistance – distFromKinect);
*pCurrTableDistance = distFromTable;
if (distFromTable > minimalFingerHeight)
{
// We will make pixel gray if it is considered a hand pixel
*pCurrImageData = 128;
}
}
}
}
}
}
}
Související články v kategorii 3D User interfaces
- Touchtable Multitouch Device With Rear Projection Ala Microsoft Surface - 3.3. 2012
- How to get OpenCV (EmguCV) Image from Primesense Kinect depth generator - 24.2. 2012
- Use your desk as mouse-free multitouch interface with MS Kinect - 18.12. 2011
- Finding points in 3D space using point quad tree - java sources - 7.3. 2011
- 3DKeyboard project - 3.2. 2011
Související články v kategorii SW development
- Legend of Grimrock - Sword of Nex solution as Autohotkey script - 8.6. 2012
- How to get OpenCV (EmguCV) Image from Primesense Kinect depth generator - 24.2. 2012
- Use your desk as mouse-free multitouch interface with MS Kinect - 18.12. 2011
- Finding points in 3D space using point quad tree - java sources - 7.3. 2011
- How to simulate vertical text (writing-mode:tb-rl) in Firefox - 29.7. 2009
