微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 硬件工程师文库 > 基于Dragonboard 410c的kinect应用系列之五——脸部识别实现代码

基于Dragonboard 410c的kinect应用系列之五——脸部识别实现代码

时间:02-20 来源:互联网 点击:

EINTRESOURCE(IDD_ABOUTBOX), hWnd, About);

break;

case IDM_EXIT:

PostQuitMessage(0);

break;

default:

return DefWindowProc(hWnd, message, wParam, lParam);

}

break;

case WM_KEYUP:

if (wParam == VK_ESCAPE)

{

PostQuitMessage(0);

}

break;

case WM_PAINT:

hdc = BeginPaint(hWnd, &ps);

// Draw the avatar window and the video window

PaintWindow(hdc, hWnd);

EndPaint(hWnd, &ps);

break;

case WM_DESTROY:

PostQuitMessage(0);

break;

default:

return DefWindowProc(hWnd, message, wParam, lParam);

}

return 0;

}

 

// Message handler for about box.

INT_PTR CALLBACK SingleFace::About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)

{

UNREFERENCED_PARAMETER(lParam);

switch (message)

{

case WM_INITDIALOG:

return (INT_PTR)TRUE;

 

case WM_COMMAND:

if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)

{

EndDialog(hDlg, LOWORD(wParam));

return (INT_PTR)TRUE;

}

break;

}

return (INT_PTR)FALSE;

}

 

// Drawing the video window

BOOL SingleFace::ShowVideo(HDC hdc, int width, int height, int originX, int originY)

{

BOOL ret = TRUE;

// Now, copy a fraction of the camera image into the screen.

IFTImage* colorImage = m_FTHelper.GetColorImage();

if (colorImage)

{

int iWidth = colorImage->GetWidth();

int iHeight = colorImage->GetHeight();

if (iWidth > 0 && iHeight > 0)

{

int iTop = 0;

int iBottom = iHeight;

int iLeft = 0;

int iRight = iWidth;

 

// Keep a separate buffer.

if (m_pVideoBuffer && SUCCEEDED(m_pVideoBuffer->Allocate(iWidth, iHeight, FTIMAGEFORMAT_UINT8_B8G8R8A8)))

{

// Copy do the video buffer while converting bytes

colorImage->CopyTo(m_pVideoBuffer, NULL, 0, 0);

 

// Compute the best approximate copy ratio.

float w1 = (float)iHeight * (float)width;

float w2 = (float)iWidth * (float)height;

if (w2 > w1 && height > 0)

{

// video image too wide

float wx = w1/height;

iLeft = (int)max(0, m_FTHelper.GetXCenterFace() - wx / 2);

iRight = iLeft + (int)wx;

if (iRight > iWidth)

{

iRight = iWidth;

iLeft = iRight - (int)wx;

}

}

else if (w1 > w2 && width > 0)

{

// video image too narrow

float hy = w2/width;

iTop = (int)max(0, m_FTHelper.GetYCenterFace() - hy / 2);

iBottom = iTop + (int)hy;

if (iBottom > iHeight)

{

iBottom = iHeight;

iTop = iBottom - (int)hy;

}

}

 

int const bmpPixSize = m_pVideoBuffer->GetBytesPerPixel();

SetStretchBltMode(hdc, HALFTONE);

BITMAPINFO bmi = {sizeof(BITMAPINFO), iWidth, iHeight, 1, static_cast<WORD>(bmpPixSize * CHAR_BIT), BI_RGB, m_pVideoBuffer->GetStride() * iHeight, 5000, 5000, 0, 0};

if (0 == StretchDIBits(hdc, originX, originY, width, height,

iLeft, iBottom, iRight-iLeft, iTop-iBottom, m_pVideoBuffer->GetBuffer(), &bmi, DIB_RGB_COLORS, SRCCOPY))

{

ret = FALSE;

}

}

}

}

return ret;

}

 

// Drawing code

BOOL SingleFace::ShowEggAvatar(HDC hdc, int width, int height, int originX, int originY)

{

static int errCount = 0;

BOOL ret = FALSE;

 

if (m_pImageBuffer && SUCCEEDED(m_pImageBuffer->Allocate(width, height, FTIMAGEFORMAT_UINT8_B8G8R8A8)))

{

memset(m_pImageBuffer->GetBuffer(), 0, m_pImageBuffer->GetStride() * height); // clear to black

 

m_eggavatar.SetScaleAndTranslationToWindow(height, width);

m_eggavatar.DrawImage(m_pImageBuffer);

BITMAPINFO bmi = {sizeof(BITMAPINFO), width, height, 1, static_cast<WORD>(m_pImageBuffer->GetB

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top