I made a Kinect Wrapper on top of the CL NUI api.
It supports a built in interface to OpenCV as well.
(I used the folowing snippet as a reference := Link ).
// Kinect.h
#ifndef KINECT
#define KINECT
#pragma comment (lib, "CLNUIDevice.lib")
#pragma comment (lib, "cv210.lib")
#pragma comment (lib, "cxcore210.lib")
#pragma comment (lib, "highgui210.lib")
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
#include <CLNUIDevice.h>
#include <Windows.h>
class Kinect{
protected:
signed DeviceCount ;
char * DeviceSerial ;
CLNUIMotor Motor ;
CLNUICamera Camera ;
bool IsCamStarted ;
PDWORD rgb32_data;
IplImage * rgb32 ;
PDWORD depth32_data ;
IplImage *depth32 ;
public:
Kinect ();
~Kinect ();
bool SetLed(unsigned State);
bool SetPosition(signed Position);
bool GetPosition(short &x, short &y, short &z);
IplImage * GetImage();
DWORD * GetPixelBuffer();
IplImage * GetDepthImage();
DWORD * GetDepthBuffer();
};
#endif
// Kinect.cpp
#include "Kinect.h"
Kinect :: Kinect ()
: DeviceCount(GetNUIDeviceCount())
, DeviceSerial(GetNUIDeviceSerial(0))
, Motor(CreateNUIMotor(DeviceSerial))
, Camera(CreateNUICamera(DeviceSerial))
, IsCamStarted(StartNUICamera(Camera))
, rgb32_data (new DWORD [640*480])
, rgb32 (cvCreateImageHeader(cvSize(640,480),8,4))
, depth32_data (new DWORD [640*480])
, depth32 (cvCreateImageHeader(cvSize(640,480),8,4))
{
}
bool Kinect :: SetLed(unsigned State){return SetNUIMotorLED( Motor, State );}
bool Kinect :: SetPosition(signed Position){return SetNUIMotorPosition(Motor,Position);}
bool Kinect :: GetPosition(short &x, short &y, short &z){return GetNUIMotorAccelerometer(this->Motor, x,y,z);
}
Kinect :: ~Kinect (){
DestroyNUIMotor(Motor);
StopNUICamera(this->Camera);
DestroyNUICamera(this->Camera);
delete [] rgb32_data ;
delete [] depth32_data ;
cvReleaseImageHeader(&this->rgb32);
cvReleaseImageHeader(&this->depth32);
}
IplImage * Kinect :: GetImage(){
cvReleaseImageHeader(&this->rgb32);
GetNUICameraColorFrameRGB32(this->Camera, this->rgb32_data ) ;
// for(int i = 0 ; i < 480 ; i++ )for(int j = 0 ; j < 640 ; j++ )this->rgb32_data[640*i+j]= 0xFF00FF ;
this->rgb32 = cvCreateImageHeader(cvSize(640,480), 8, 4);
cvSetData(this->rgb32, this->rgb32_data, rgb32->widthStep);
return &*rgb32 ;
}
DWORD * Kinect :: GetPixelBuffer(){
GetNUICameraColorFrameRGB32(this->Camera, this->rgb32_data ) ;
return &*rgb32_data ;
}
IplImage * Kinect :: GetDepthImage(){
cvReleaseImageHeader(&this->depth32);
GetNUICameraDepthFrameRGB32(this->Camera, this->depth32_data ) ;
// for(int i = 0 ; i < 480 ; i++ )for(int j = 0 ; j < 640 ; j++ )this->rgb32_data[640*i+j]= 0xFF00FF ;
this->depth32 = cvCreateImageHeader(cvSize(640,480), 8, 4);
cvSetData(this->depth32, this->depth32_data, rgb32->widthStep);
return &*depth32 ;
}
DWORD * Kinect :: GetDepthBuffer(){
GetNUICameraDepthFrameRGB32(this->Camera, this->depth32_data ) ;
return &*depth32_data ;
}
#include "Kinect.h"
void main(){
cvNamedWindow( "A", CV_WINDOW_AUTOSIZE );
Kinect * k = new Kinect();
// k->SetLed(7);
//k->SetPosition(0);
do{
IplImage * frame = k->GetDepthImage();
cvShowImage( "A", frame );
cvWaitKey(1);
} while (!GetAsyncKeyState(0x50));
delete k ;
}
}
Hope it will help someone, Have Fun!