这个是用Kinect做三维扫描时的第一步,就是将感兴趣的前景部分取下来。大家都知道,Kinect的最大特点就是可以采集到深度数据,利用深度数据就可以将前景和背景区分开来。
长话短说,先上效果图吧。
再上源代码:
/***************************************
* Description:This program can rebuild
* models by scanning objects with kinect
*
* Methods of application:
*
*
* Author:Lixam
* Time:2012-11
****************************************/
#include "stdafx.h"
#include <XnCppWrapper.h>
#include <opencv/highgui.h>
#include <opencv/cv.h>
#include <vector>
using namespace cv;
using namespace xn;
using namespace std;
#define IMAGEWIDTH 640
#define IMAGEHEIGTH 480
typedef struct
{
unsigned char R;
unsigned char G;
unsigned char B;
}RGBPIXEL;
typedef struct
{
unsigned char data_L; //Low bits
unsigned char data_H; //Heigh bits
}DEPTHPIXEL;
//Generator
ImageGenerator m_imageGenerator;
DepthGenerator m_depthGenerator;
Context m_context;
/*************************************************************************
*
* GetROIdata()
*
* Parameters:
*
* IplImage* image - Source of color image data
* IplImage* depth - Source of color depth data
* vector<RGBPIXEL>& ROIimage - Co