细心的朋友肯定已经发现Kinect上长了三只眼睛,其中一个是彩色摄像头,另外两个深度摄像头,一个负责发射红外光,一个负责接收,这样,我们便能通过Kinect得到一幅彩色图像和一幅深度图像。如果大家对Kniect眼睛的技术细节感兴趣,请点击这里。
小斤的第一个范例,便是通过OpenNI得到彩色和深度图像咯,代码不长,其中一部分参考了Heresky童鞋的文章《透過 OpneNI 合併 Kinect 深度以及彩色影像資料》,此外,小斤补充了OpenCV的显示部分,使范例更为直观。
#include <stdlib.h>
#include <iostream>
#include <string>
//【1】
#include <XnCppWrapper.h>
#include "opencv/cv.h"
#include "opencv/highgui.h"
using namespace std;
using namespace cv;
void CheckOpenNIError( XnStatus result, string status )
{
if( result != XN_STATUS_OK )
cerr << status << " Error: " << xnGetStatusString( result ) << endl;
}
int main( int argc, cha