I've provided this answer in the past.
Personally I've used the Xbox360 sensor with OpenNI the most (because it's cross platform). Also the NITE middleware on alongside OpenNI provides some basic hand detection and even gesture detection (swipes, circle gesture, "button" push, etc.).
While OpenNI is opensource, NITE isn't so you'd be limited to what they provide.
The links you've shared use OpenCV. You can install OpenNI and compile OpenCV from source with OpenNI support. Alternatively, you can manually wrap the OpenNI frame data into an OpenCV cv::Mat
and carry on with the OpenCV operations from there.
Here's a basic example that uses OpenNI to get the depth data and passes that to OpenCV:
#include <OpenNI.h>
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/videoio/videoio.hpp"
#include <iostream>
using namespace cv;
using namespace std;
int main() {
// setup OpenNI
openni::Status rc = openni::STATUS_OK;
openni::Device device;
openni::VideoStream depth, color;
const char* deviceURI = openni::ANY_DEVICE;
rc = openni::OpenNI::initialize();
printf("After initialization:\n%s\n", openni::OpenNI::getExtendedError());
rc = device.open(deviceURI);
if (rc != openni::STATUS_OK)
{
printf("Device open failed:\n%s\n", openni::OpenNI::getExtendedError());
openni::OpenNI::shutdown();
return 1;
}
rc = depth.create(device, openni::SENSOR_DEPTH);
if (rc == openni::STATUS_OK)
{
rc = depth.start();
if (rc != openni::STATUS_OK)
{
printf("Couldn't start depth stream:\n%s\n", openni::OpenNI::getExtendedError());
depth.destroy();
}
}
else
{
printf("Couldn't find depth stream:\n%s\n", openni::OpenNI::getExtendedError());
}
if (!depth.isValid())
{
printf("No valid depth stream. Exiting\n");
openni::OpenNI::shutdown();
return 2;
}
openni::VideoMode vm = depth.getVideoMode();
int cols, rows;
cols = vm.getResolutionX();
rows = vm.getResolutionY();
openni::VideoFrameRef frame;
depth.start();
// main loop
for (;;) {
// read OpenNI frame
depth.readFrame(&frame);
// get depth pixel data
openni::DepthPixel* dData = (openni::DepthPixel*)frame.getData();
// wrap the data in an OpenCV Mat
Mat depthMat(rows, cols, CV_16UC1, dData);
// for visualisation only remap depth values
Mat depthShow;
const float scaleFactor = 0.05f;
depthMat.convertTo(depthShow, CV_8UC1, scaleFactor);
if(!depthShow.empty())
{
imshow("depth", depthShow);
}
if (waitKey(30) == 27) break;
}
// OpenNI exit cleanup
depth.stop();
openni::OpenNI::shutdown();
}
One of the tutorials you've linked to (https://github.com/royshil/OpenHPE) uses libfreenect
which is another great cross platform option to interface with the old Kinect.
FWIW, Kinect for XBox One has better depth data, deals better with direct sunlight and the SDK has support for custom gesture recognition (see this tutorial for example).