在继《基于qualcomm平台的kinect教程三之获取深度图》之后,今天我们来获取下人体的骨骼图。
一.核心代码:
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//------------------------------------------------------------------------------
#include "stdafx.h"
#include
#include "SkeletonBasics.h"
#include "resource.h"
static const float g_JointThickness = 3.0f;
static const float g_TrackedBoneThickness = 6.0f;
static const float g_InferredBoneThickness = 1.0f;
///
/// Entry point for the application
///
///
handle to the application instance
///
always 0
///
command line arguments
///
whether to display minimized, maximized, or normally
///
status
int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow)
{
CSkeletonBasics application;
application.Run(hInstance, nCmdShow);
}
///
/// Constructor
///
CSkeletonBasics::CSkeletonBasics() :
m_pD2DFactory(NULL),
m_hNextSkeletonEvent(INVALID_HANDLE_VALUE),
m_pSkeletonStreamHandle(INVALID_HANDLE_VALUE),
m_bSeatedMode(false),
m_pRenderTarget(NULL),
m_pBrushJointTracked(NULL),
m_pBrushJointInferred(NULL),
m_pBrushBoneTracked(NULL),
m_pBrushBoneInferred(NULL),
m_pNuiSensor(NULL)
{
ZeroMemory(m_Points,sizeof(m_Points));
}
///
/// Destructor
///
CSkeletonBasics::~CSkeletonBasics()
{
if (m_pNuiSensor)
{
m_pNuiSensor->NuiShutdown();
}
if (m_hNextSkeletonEvent && (m_hNextSkeletonEvent != INVALID_HANDLE_VALUE))
{
CloseHandle(m_hNextSkeletonEvent);
}
// clean up Direct2D objects
DiscardDirect2DResources();
// clean up Direct2D
SafeRelease(m_pD2DFactory);
SafeRelease(m_pNuiSensor);
}
///
/// Creates the main window and begins processing
///
///
handle to the application instance
///
whether to display minimized, maximized, or normally
int CSkeletonBasics::Run(HINSTANCE hInstance, int nCmdShow)
{
MSG msg = {0};
WNDCLASS wc = {0};
// Dialog custom window class
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.cbWndExtra = DLGWINDOWEXTRA;
wc.hInstance = hInstance;
wc.hCursor = LoadCursorW(NULL, IDC_ARROW);
wc.hIcon = LoadIconW(hInstance, MAKEINTRESOURCE(IDI_APP));
wc.lpfnWndProc = DefDlgProcW;
wc.lpszClassName = L"SkeletonBasicsAppDlgWndClass";
if (!RegisterClassW(&wc))
{
return 0;
}
// Create main application window
HWND hWndApp = CreateDialogParamW(
hInstance,
MAKEINTRESOURCE(IDD_APP),
NULL,
(DLGPROC)CSkeletonBasics::MessageRouter,
reinterpret_cast
(this));
// Show window
ShowWindow(hWndApp, nC