9#ifdef ENABLE_KINECT_SDK
18CKinectFaceTracker::CKinectFaceTracker(
void)
33void CKinectFaceTracker::free(
void)
41 if (m_image_data!=NULL) {
42 m_image_data->Release();
46 if (m_depth_data!=NULL) {
47 m_depth_data->Release();
51 if (m_tracker!=NULL) {
59BOOL CKinectFaceTracker::create(
int width,
int height, uByte* image, uByte* depth)
61 if (image==NULL || depth==NULL)
return FALSE;
63 m_tracker = FTCreateFaceTracker();
64 if (m_tracker==NULL)
return FALSE;
67 FT_CAMERA_CONFIG image_config;
68 FT_CAMERA_CONFIG depth_config;
70 image_config.Width = width;
71 image_config.Height = height;
72 image_config.FocalLength = NUI_CAMERA_COLOR_NOMINAL_FOCAL_LENGTH_IN_PIXELS*(width/640.0f);
74 depth_config.Width = width;
75 depth_config.Height = height;
76 depth_config.FocalLength = NUI_CAMERA_DEPTH_NOMINAL_FOCAL_LENGTH_IN_PIXELS*(width/320.0f);
78 HRESULT hr = m_tracker->Initialize(&image_config, &depth_config, NULL, NULL);
85 hr = m_tracker->CreateFTResult(&m_result);
91 m_image_data = FTCreateImage();
92 m_depth_data = FTCreateImage();
93 if (!m_image_data || !m_depth_data) {
98 m_image_data->Attach(width, height, image, FTIMAGEFORMAT_UINT8_B8G8R8X8, width*4);
99 m_depth_data->Attach(width, height, depth, FTIMAGEFORMAT_UINT16_D13P3, width*2);
102 m_sensor.pVideoFrame = m_image_data;
103 m_sensor.pDepthFrame = m_depth_data;
104 m_sensor.ZoomFactor = 1.0f;
105 m_sensor.ViewOffset.x = 0;
106 m_sensor.ViewOffset.y = 0;
113BOOL CKinectFaceTracker::detect(FT_VECTOR3D* hint)
115 if (m_tracker==NULL)
return FALSE;
118 HRESULT hr = m_tracker->ContinueTracking(&m_sensor, hint, m_result);
119 if (FAILED(hr) || FAILED(m_result->GetStatus())) is_detected = FALSE;
123 HRESULT hr = m_tracker->StartTracking(&m_sensor, NULL, hint, m_result);
124 if (SUCCEEDED(hr) && SUCCEEDED(m_result->GetStatus())) is_detected = TRUE;
132RECT CKinectFaceTracker::getFaceRect(
void)
136 this->m_result->GetFaceRect(&rect);
142Vector<float> CKinectFaceTracker::getFaceEulerXYZ(
void)
144 Vector<float> eul(0.0, 0.0, 0.0, 0.0, -1.0);
150 HRESULT hr = m_result->Get3DPose(&scale, rotXYZ, posXYZ);
151 if (FAILED(hr))
return eul;
153 eul.set((
float)(rotXYZ[0]*DEGREE2RAD), (
float)(rotXYZ[1]*DEGREE2RAD), (
float)(rotXYZ[2]*DEGREE2RAD));
160void CKinectFaceTracker::drawFaceRect(ExCmnHead* viewdata,
int scale, BOOL mirror,
int col,
int line)
162 if (is_detected && viewdata!=NULL) {
164 MSGraph<unsigned int> vp;
165 vp.xs = viewdata->xsize;
166 vp.ys = viewdata->ysize;
168 vp.gp = (
unsigned int*)viewdata->grptr;
170 RECT rect = getFaceRect();
173 ye = rect.bottom/scale;
175 if (scale<=0) scale = 1;
177 xs = rect.left/scale;
178 xe = rect.right/scale;
181 xs = vp.xs - rect.left/scale - 1;
182 xe = vp.xs - rect.right/scale - 1;
185 MSGraph_Box(vp, xs, ys, xe, ye, col);
186 for (
int i=1; i<line; i++) {
187 MSGraph_Box(vp, xs-i, ys-i, xe+i, ye+i, col);
188 MSGraph_Box(vp, xs+i, ys+i, xe-i, ye-i, col);