Ejemplo n.º 1
0
// In this function, we save the instance handle, then create and display the main program window.
BOOL SingleFace::InitInstance(HINSTANCE hInstance, PWSTR lpCmdLine, int nCmdShow)
{
    m_hInst = hInstance; // Store instance handle in our global variable

    ParseCmdString(lpCmdLine);

    WCHAR szTitle[MaxLoadStringChars];                  // The title bar text
    LoadString(m_hInst, IDS_APP_TITLE, szTitle, ARRAYSIZE(szTitle));

    static const PCWSTR RES_MAP[] = { L"80x60", L"320x240", L"640x480", L"1280x960" };
    static const PCWSTR IMG_MAP[] = { L"PLAYERID", L"RGB", L"YUV", L"YUV_RAW", L"DEPTH" };

    // Add mode params in title
    WCHAR szTitleComplete[MAX_PATH];
    swprintf_s(szTitleComplete, L"%s -- Depth:%s:%s Color:%s:%s NearMode:%s, SeatedSkeleton:%s", szTitle,
        IMG_MAP[m_depthType], (m_depthRes < 0)? L"ERROR": RES_MAP[m_depthRes], IMG_MAP[m_colorType], (m_colorRes < 0)? L"ERROR": RES_MAP[m_colorRes], m_bNearMode? L"ON": L"OFF",
        m_bSeatedSkeletonMode?L"ON": L"OFF");

    WCHAR szWindowClass[MaxLoadStringChars];            // the main window class name
    LoadString(m_hInst, IDC_SINGLEFACE, szWindowClass, ARRAYSIZE(szWindowClass));

    RegisterClass(szWindowClass);

    m_hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_SINGLEFACE));

    m_pImageBuffer = FTCreateImage();
    m_pVideoBuffer = FTCreateImage();

    m_hWnd = CreateWindow(szWindowClass, szTitleComplete, WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT, 0, WINDOWWIDTH, WINDOWHEIGHT, NULL, NULL, m_hInst, this);
    if (!m_hWnd)
    {
        return FALSE;
    }

    ShowWindow(m_hWnd, nCmdShow);
    UpdateWindow(m_hWnd);

#ifdef USEOPENGL
	m_GLContext.init(m_hWnd);
	InitGL();
#endif

    return SUCCEEDED(m_FTHelper.Init(m_hWnd,
        FTHelperCallingBack,
        this,
        m_depthType,
        m_depthRes,
        m_bNearMode,
        TRUE, // if near mode doesn't work, fall back to default mode
        m_colorType,
        m_colorRes,
        m_bSeatedSkeletonMode));
}
Ejemplo n.º 2
0
void initFaceTracker(void)
{
    HRESULT hr;
    pFaceTracker = FTCreateFaceTracker(NULL);	// We don't use any options.
    if(!pFaceTracker) {
        STDERR("Could not create the face tracker.\r\n");
        return;
    }

    FT_CAMERA_CONFIG videoConfig;
    videoConfig.Width = 640;
    videoConfig.Height = 480;
    videoConfig.FocalLength = NUI_CAMERA_COLOR_NOMINAL_FOCAL_LENGTH_IN_PIXELS;			// 640x480
    //videoConfig.FocalLength = NUI_CAMERA_COLOR_NOMINAL_FOCAL_LENGTH_IN_PIXELS * 2.f;	// 1280x960

    FT_CAMERA_CONFIG depthConfig;
    depthConfig.Width = 320;
    depthConfig.Height = 240;
    //depthConfig.FocalLength = NUI_CAMERA_DEPTH_NOMINAL_FOCAL_LENGTH_IN_PIXELS / 4.f;	//  80x 60
    depthConfig.FocalLength = NUI_CAMERA_DEPTH_NOMINAL_FOCAL_LENGTH_IN_PIXELS;			// 320x240
    //depthConfig.FocalLength = NUI_CAMERA_DEPTH_NOMINAL_FOCAL_LENGTH_IN_PIXELS * 2.f;	// 640x480

    hr = pFaceTracker->Initialize(&videoConfig, &depthConfig, NULL, NULL);
    if(!pFaceTracker) {
        STDERR("Could not initialize the face tracker.\r\n");
        return;
    }

    hr = pFaceTracker->CreateFTResult(&pFTResult);
    if (FAILED(hr) || !pFTResult)
    {
        STDERR("Could not initialize the face tracker result.\r\n");
        return;
    }

    iftColorImage = FTCreateImage();
    if (!iftColorImage || FAILED(hr = iftColorImage->Allocate(videoConfig.Width, videoConfig.Height, FTIMAGEFORMAT_UINT8_B8G8R8X8)))
    {
        STDERR("Could not create the color image.\r\n");
        return;
    }
    iftDepthImage = FTCreateImage();
    if (!iftDepthImage || FAILED(hr = iftDepthImage->Allocate(320, 240, FTIMAGEFORMAT_UINT16_D13P3)))
    {
        STDERR("Could not create the depth image.\r\n");
        return;
    }

    lastTrackSucceeded = false;
    faceScale = 0;
}
// In this function, we save the instance handle, then create and display the main program window.
BOOL MultiFace::InitInstance(HINSTANCE hInstance, PWSTR lpCmdLine, int nCmdShow)
{
    ParseCmdString(lpCmdLine);

    m_eggavatar = new EggAvatar[m_nbUsers];
    m_pImageBuffer = new IFTImage*[m_nbUsers];
    
    m_hInst = hInstance; // Store instance handle in our global variable

    WCHAR szTitle[MaxLoadStringChars];                  // The title bar text
    LoadString(m_hInst, IDS_APP_TITLE, szTitle, ARRAYSIZE(szTitle));

    static const PCWSTR RES_MAP[] = { L"80x60", L"320x240", L"640x480", L"1280x960" };
    static const PCWSTR IMG_MAP[] = { L"PLAYERID", L"RGB", L"YUV", L"YUV_RAW", L"DEPTH" };

    // Add mode params in title
    WCHAR szTitleComplete[MAX_PATH];
    swprintf_s(szTitleComplete, L"%s -- Depth:%s:%s Color:%s:%s NearMode:%s SeatedSkeleton:%s", szTitle,
        IMG_MAP[m_depthType], (m_depthRes < 0)? L"ERROR": RES_MAP[m_depthRes], IMG_MAP[m_colorType], (m_colorRes < 0)? L"ERROR": RES_MAP[m_colorRes], m_bNearMode? L"ON": L"OFF", m_bSeatedSkeletonMode? L"ON": L"OFF");

    WCHAR szWindowClass[MaxLoadStringChars];            // the main window class name
    LoadString(m_hInst, IDC_MULTIFACE, szWindowClass, ARRAYSIZE(szWindowClass));

    RegisterClass(szWindowClass);

    m_hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_MULTIFACE));

    for (UINT i=0; i<m_nbUsers; i++)
    {
        m_pImageBuffer[i] = FTCreateImage();
    }
    m_pVideoBuffer = FTCreateImage();

    m_hWnd = CreateWindow(szWindowClass, szTitleComplete, WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, m_hInst, this);
    if (!m_hWnd)
    {
        return FALSE;
    }
   
   ShowWindow(m_hWnd, nCmdShow);
   UpdateWindow(m_hWnd);

   // Start the face tracking.
   return SUCCEEDED(m_FTHelper.Init(m_hWnd, m_nbUsers, FTHelperCallingBack, this, FTHelperUserSelection, this, m_depthType, m_depthRes, m_bNearMode, m_colorType, m_colorRes, m_bSeatedSkeletonMode));
}
HRESULT NuiDepthStream::FTdepthInit(FT_CAMERA_CONFIG DepthCameraConfig)
{
	HRESULT hr;
    m_pFTdepthBuffer=FTCreateImage();
	hr = m_pFTdepthBuffer->Allocate(DepthCameraConfig.Width, DepthCameraConfig.Height, FTIMAGEFORMAT_UINT16_D13P3);
	if (!m_pFTdepthBuffer||FAILED(hr)) 
		return E_OUTOFMEMORY;
	return hr;
}
Ejemplo n.º 5
0
HRESULT KinectSensor::Init(NUI_IMAGE_TYPE depthType, NUI_IMAGE_RESOLUTION depthRes, BOOL bNearMode, BOOL bFallbackToDefault, NUI_IMAGE_TYPE colorType, NUI_IMAGE_RESOLUTION colorRes, BOOL bSeatedSkeletonMode)
{
    HRESULT hr = E_UNEXPECTED;

    Release(); // Deal with double initializations.

    //do not support NUI_IMAGE_TYPE_COLOR_RAW_YUV for now
    if(colorType != NUI_IMAGE_TYPE_COLOR && colorType != NUI_IMAGE_TYPE_COLOR_YUV
        || depthType != NUI_IMAGE_TYPE_DEPTH_AND_PLAYER_INDEX && depthType != NUI_IMAGE_TYPE_DEPTH)
    {
        return E_INVALIDARG;
    }

    m_VideoBuffer = FTCreateImage();
    if (!m_VideoBuffer)
    {
        return E_OUTOFMEMORY;
    }

    DWORD width = 0;
    DWORD height = 0;

    NuiImageResolutionToSize(colorRes, width, height);

    hr = m_VideoBuffer->Allocate(width, height, FTIMAGEFORMAT_UINT8_B8G8R8X8);
    if (FAILED(hr))
    {
        return hr;
    }

    m_DepthBuffer = FTCreateImage();
    if (!m_DepthBuffer)
    {
        return E_OUTOFMEMORY;
    }

    NuiImageResolutionToSize(depthRes, width, height);

    hr = m_DepthBuffer->Allocate(width, height, FTIMAGEFORMAT_UINT16_D13P3);
    if (FAILED(hr))
    {
        return hr;
    }
    
    m_FramesTotal = 0;
    m_SkeletonTotal = 0;

    for (int i = 0; i < NUI_SKELETON_COUNT; ++i)
    {
        m_HeadPoint[i] = m_NeckPoint[i] = FT_VECTOR3D(0, 0, 0);
        m_SkeletonTracked[i] = false;
    }

    m_hNextDepthFrameEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
    m_hNextVideoFrameEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
    m_hNextSkeletonEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
    
    DWORD dwNuiInitDepthFlag = (depthType == NUI_IMAGE_TYPE_DEPTH)? NUI_INITIALIZE_FLAG_USES_DEPTH : NUI_INITIALIZE_FLAG_USES_DEPTH_AND_PLAYER_INDEX;

    hr = NuiInitialize(dwNuiInitDepthFlag | NUI_INITIALIZE_FLAG_USES_SKELETON | NUI_INITIALIZE_FLAG_USES_COLOR);
    if (FAILED(hr))
    {
        return hr;
    }
    m_bNuiInitialized = true;

	DWORD dwSkeletonFlags = NUI_SKELETON_TRACKING_FLAG_ENABLE_IN_NEAR_RANGE;
	if (bSeatedSkeletonMode)
	{
		dwSkeletonFlags |= NUI_SKELETON_TRACKING_FLAG_ENABLE_SEATED_SUPPORT;
	}
    hr = NuiSkeletonTrackingEnable( m_hNextSkeletonEvent, dwSkeletonFlags );
    if (FAILED(hr))
    {
        return hr;
    }

    hr = NuiImageStreamOpen(
        colorType,
        colorRes,
        0,
        2,
        m_hNextVideoFrameEvent,
        &m_pVideoStreamHandle );
    if (FAILED(hr))
    {
        return hr;
    }

    hr = NuiImageStreamOpen(
        depthType,
        depthRes,
        (bNearMode)? NUI_IMAGE_STREAM_FLAG_ENABLE_NEAR_MODE : 0,
        2,
        m_hNextDepthFrameEvent,
        &m_pDepthStreamHandle );
    if (FAILED(hr))
    {
        if(bNearMode && bFallbackToDefault)
        {
            hr = NuiImageStreamOpen(
                depthType,
                depthRes,
                0,
                2,
                m_hNextDepthFrameEvent,
                &m_pDepthStreamHandle );
        }

        if(FAILED(hr))
        {
            return hr;
        }
    }

    // Start the Nui processing thread
    m_hEvNuiProcessStop=CreateEvent(NULL,TRUE,FALSE,NULL);
    m_hThNuiProcess=CreateThread(NULL,0,ProcessThread,this,0,NULL);

    return hr;
}
Ejemplo n.º 6
0
DWORD WINAPI FTHelper2::FaceTrackingThread()
{
    FT_CAMERA_CONFIG videoConfig;
    FT_CAMERA_CONFIG depthConfig;
    FT_CAMERA_CONFIG* pDepthConfig = NULL;

    // Try to get the Kinect camera to work
    HRESULT hr = m_KinectSensor.Init(m_depthType, m_depthRes, m_bNearMode, FALSE, m_colorType, m_colorRes, m_bSeatedSkeleton);
    if (SUCCEEDED(hr))
    {
        m_KinectSensorPresent = TRUE;
        m_KinectSensor.GetVideoConfiguration(&videoConfig);
        m_KinectSensor.GetDepthConfiguration(&depthConfig);
        pDepthConfig = &depthConfig;
    }
    else
    {
        m_KinectSensorPresent = FALSE;

        MessageBoxW(m_hWnd, L"Could not initialize the Kinect sensor.\n", L"Face Tracker Initialization Error\n", MB_OK);
        return 1;
    }

    m_UserContext = new FTHelperContext[m_nbUsers];
    if (m_UserContext != 0)
    {
        memset(m_UserContext, 0, sizeof(FTHelperContext)*m_nbUsers);
    }
    else
    {
        MessageBoxW(m_hWnd, L"Could not allocate user context array.\n", L"Face Tracker Initialization Error\n", MB_OK);
        return 2;
    }

    for (UINT i=0; i<m_nbUsers; i++)
    {
        // Try to start the face tracker.
        m_UserContext[i].m_pFaceTracker = FTCreateFaceTracker(_opt);
        if (!m_UserContext[i].m_pFaceTracker)
        {
            MessageBoxW(m_hWnd, L"Could not create the face tracker.\n", L"Face Tracker Initialization Error\n", MB_OK);
            return 3;
        }

        hr = m_UserContext[i].m_pFaceTracker->Initialize(&videoConfig, pDepthConfig, NULL, NULL);
        if (FAILED(hr))
        {
            WCHAR path[512], buffer[1024];
            GetCurrentDirectoryW(ARRAYSIZE(path), path);
            wsprintf(buffer, L"Could not initialize face tracker (%s) for user %d.\n", path, i);

            MessageBoxW(m_hWnd, buffer, L"Face Tracker Initialization Error\n", MB_OK);

            return 4;
        }
        m_UserContext[i].m_pFaceTracker->CreateFTResult(&m_UserContext[i].m_pFTResult);
        if (!m_UserContext[i].m_pFTResult)
        {
            MessageBoxW(m_hWnd, L"Could not initialize the face tracker result for user %d.\n", L"Face Tracker Initialization Error\n", MB_OK);
            return 5;
        }
        m_UserContext[i].m_LastTrackSucceeded = false;
    }

    // Initialize the RGB image.
    m_colorImage = FTCreateImage();
    if (!m_colorImage || FAILED(hr = m_colorImage->Allocate(videoConfig.Width, videoConfig.Height, FTIMAGEFORMAT_UINT8_B8G8R8X8)))
    {
        return 6;
    }

    if (pDepthConfig)
    {
        m_depthImage = FTCreateImage();
        if (!m_depthImage || FAILED(hr = m_depthImage->Allocate(depthConfig.Width, depthConfig.Height, FTIMAGEFORMAT_UINT16_D13P3)))
        {
            return 7;
        }
    }

    SetCenterOfImage(NULL);

    while (m_ApplicationIsRunning)
    {
        CheckCameraInput();
        InvalidateRect(m_hWnd, NULL, FALSE);
        UpdateWindow(m_hWnd);
        Sleep(16);
    }
    return 0;
}