我过去提供过this answer。
我个人最常使用带有 OpenNI 的 Xbox360 传感器(因为它是跨平台的)。此外,OpenNI 旁边的 NITE 中间件提供了一些基本的手部检测甚至手势检测(滑动、圆形手势、“按钮”推送等)。
虽然 OpenNI 是开源的,但 NITE 并非如此,因此您将受限于它们提供的内容。
您共享的链接使用 OpenCV。您可以安装 OpenNI 并从支持 OpenNI 的源代码编译 OpenCV。或者,您可以手动将 OpenNI 帧数据包装到 OpenCV cv::Mat 中,然后从那里继续执行 OpenCV 操作。
这是一个使用 OpenNI 获取深度数据并将其传递给 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();
}
您链接到的教程之一 (https://github.com/royshil/OpenHPE) 使用 libfreenect,这是与旧版 Kinect 交互的另一个很棒的跨平台选项。
FWIW,Xbox One 的 Kinect 具有更好的深度数据,更好地处理阳光直射,并且 SDK 支持自定义手势识别(例如,参见 this tutorial)。