基于Dragonboard 410c的kinect应用系列之五——脸部识别实现代码
ytesPerPixel() * CHAR_BIT), BI_RGB, m_pImageBuffer->GetStride() * height, 5000, 5000, 0, 0};
errCount += (0 == StretchDIBits(hdc, 0, 0, width, height, 0, 0, width, height, m_pImageBuffer->GetBuffer(), &bmi, DIB_RGB_COLORS, SRCCOPY));
ret = TRUE;
}
return ret;
}
// Draw the egg head and the camera video with the mask superimposed.
BOOL SingleFace::PaintWindow(HDC hdc, HWND hWnd)
{
static int errCount = 0;
BOOL ret = FALSE;
RECT rect;
GetClientRect(hWnd, &rect);
int width = rect.right - rect.left;
int height = rect.bottom - rect.top;
int halfWidth = width/2;
// Show the video on the right of the window
errCount += !ShowVideo(hdc, width - halfWidth, height, halfWidth, 0);
// Draw the egg avatar on the left of the window
errCount += !ShowEggAvatar(hdc, halfWidth, height, 0, 0);
return ret;
}
/*
* The "Face Tracker" helper class is generic. It will call back this function
* after a face has been successfully tracked. The code in the call back passes the parameters
* to the Egg Avatar, so it can be animated.
*/
void SingleFace::FTHelperCallingBack(PVOID pVoid)
{
SingleFace* pApp = reinterpret_cast<SingleFace*>(pVoid);
if (pApp)
{
IFTResult* pResult = pApp->m_FTHelper.GetResult();
if (pResult && SUCCEEDED(pResult->GetStatus()))
{
FLOAT* pAU = NULL;
UINT numAU;
pResult->GetAUCoefficients(&pAU, &numAU);
pApp->m_eggavatar.SetCandideAU(pAU, numAU);
FLOAT scale;
FLOAT rotationXYZ[3];
FLOAT translationXYZ[3];
pResult->Get3DPose(&scale, rotationXYZ, translationXYZ);
pApp->m_eggavatar.SetTranslations(translationXYZ[0], translationXYZ[1], translationXYZ[2]);
pApp->m_eggavatar.SetRotations(rotationXYZ[0], rotationXYZ[1], rotationXYZ[2]);
}
}
}
void SingleFace::ParseCmdString(PWSTR lpCmdLine)
{
const WCHAR KEY_DEPTH[] = L"-Depth";
const WCHAR KEY_COLOR[] = L"-Color";
const WCHAR KEY_NEAR_MODE[] = L"-NearMode";
const WCHAR KEY_DEFAULT_DISTANCE_MODE[] = L"-DefaultDistanceMode";
const WCHAR KEY_SEATED_SKELETON_MODE[] = L"-SeatedSkeleton";
const WCHAR STR_NUI_IMAGE_TYPE_DEPTH[] = L"DEPTH";
const WCHAR STR_NUI_IMAGE_TYPE_DEPTH_AND_PLAYER_INDEX[] = L"PLAYERID";
const WCHAR STR_NUI_IMAGE_TYPE_COLOR[] = L"RGB";
const WCHAR STR_NUI_IMAGE_TYPE_COLOR_YUV[] = L"YUV";
const WCHAR STR_NUI_IMAGE_RESOLUTION_80x60[] = L"80x60";
const WCHAR STR_NUI_IMAGE_RESOLUTION_320x240[] = L"320x240";
const WCHAR STR_NUI_IMAGE_RESOLUTION_640x480[] = L"640x480";
const WCHAR STR_NUI_IMAGE_RESOLUTION_1280x960[] = L"1280x960";
enum TOKEN_ENUM
{
TOKEN_ERROR,
TOKEN_DEPTH,
TOKEN_COLOR,
TOKEN_NEARMODE,
TOKEN_DEFAULTDISTANCEMODE,
TOKEN_SEATEDSKELETON
};
int argc = 0;
LPWSTR *argv = CommandLineToArgvW(lpCmdLine, &argc);
for(int i = 0; i < argc; i++)
{
NUI_IMAGE_TYPE* pType = NULL;
NUI_IMAGE_RESOLUTION* pRes = NULL;
TOKEN_ENUM tokenType = TOKEN_ERROR;
PWCHAR context = NULL;
PWCHAR token = wcstok_s(argv[i], L":", &context);
if(0 == wcsncmp(token, KEY_DEPTH, ARRAYSIZE(KEY_DEPTH)))
{
tokenType = TOKEN_DEPTH;
pType = &m_depthType;
pRes = &m_depthRes;
}
else if(0 == wcsncmp(token, KEY_COLOR, ARRAYSIZE(KEY_COLOR)))
{
tokenType = TOKEN_COLOR;
pType = &m_colorType;
pRes = &m_colorRes;
DragonBoard 410c 脸部识别 Kinect 相关文章: