微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 硬件工程师文库 > 基于Dragonboard 410c的kinect应用系列之四——获取人体骨骼图

基于Dragonboard 410c的kinect应用系列之四——获取人体骨骼图

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

el, NUI_SKELETON_POSITION_INDEX joint0, NUI_SKELETON_POSITION_INDEX joint1)

{

NUI_SKELETON_POSITION_TRACKING_STATE joint0State = skel.eSkeletonPositionTrackingState[joint0];

NUI_SKELETON_POSITION_TRACKING_STATE joint1State = skel.eSkeletonPositionTrackingState[joint1];

 

// If we can't find either of these joints, exit

if (joint0State == NUI_SKELETON_POSITION_NOT_TRACKED || joint1State == NUI_SKELETON_POSITION_NOT_TRACKED)

{

return;

}

 

// Don't draw if both points are inferred

if (joint0State == NUI_SKELETON_POSITION_INFERRED && joint1State == NUI_SKELETON_POSITION_INFERRED)

{

return;

}

 

// We assume all drawn bones are inferred unless BOTH joints are tracked

if (joint0State == NUI_SKELETON_POSITION_TRACKED && joint1State == NUI_SKELETON_POSITION_TRACKED)

{

m_pRenderTarget->DrawLine(m_Points[joint0], m_Points[joint1], m_pBrushBoneTracked, g_TrackedBoneThickness);

}

else

{

m_pRenderTarget->DrawLine(m_Points[joint0], m_Points[joint1], m_pBrushBoneInferred, g_InferredBoneThickness);

}

}

 

/// <summary>

/// Converts a skeleton point to screen space

/// </summary>

/// <param name="skeletonPoint">skeleton point to tranform</param>

/// <param name="width">width (in pixels) of output buffer</param>

/// <param name="height">height (in pixels) of output buffer</param>

/// <returns>point in screen-space</returns>

D2D1_POINT_2F CSkeletonBasics::SkeletonToScreen(Vector4 skeletonPoint, int width, int height)

{

LONG x, y;

USHORT depth;

 

// Calculate the skeleton's position on the screen

// NuiTransformSkeletonToDepthImage returns coordinates in NUI_IMAGE_RESOLUTION_320x240 space

NuiTransformSkeletonToDepthImage(skeletonPoint, &x, &y, &depth);

 

float screenPointX = static_cast<float>(x * width) / cScreenWidth;

float screenPointY = static_cast<float>(y * height) / cScreenHeight;

 

return D2D1::Point2F(screenPointX, screenPointY);

}

 

/// <summary>

/// Ensure necessary Direct2d resources are created

/// </summary>

/// <returns>S_OK if successful, otherwise an error code</returns>

HRESULT CSkeletonBasics::EnsureDirect2DResources()

{

HRESULT hr = S_OK;

 

// If there isn't currently a render target, we need to create one

if (NULL == m_pRenderTarget)

{

RECT rc;

GetWindowRect( GetDlgItem( m_hWnd, IDC_VIDEOVIEW ), &rc );

 

int width = rc.right - rc.left;

int height = rc.bottom - rc.top;

D2D1_SIZE_U size = D2D1::SizeU( width, height );

D2D1_RENDER_TARGET_PROPERTIES rtProps = D2D1::RenderTargetProperties();

rtProps.pixelFormat = D2D1::PixelFormat( DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_IGNORE);

rtProps.usage = D2D1_RENDER_TARGET_USAGE_GDI_COMPATIBLE;

="line" id="LC503"> // Create a Hwnd render target, in order to render to the window set in initialize

="line" id="LC504"> hr = m_pD2DFactory->CreateHwndRenderTarget(

="line" id="LC505"> rtProps,

="line" id="LC506"> D2D1::HwndRenderTargetProperties(GetDlgItem( m_hWnd, IDC_VIDEOVIEW), size),

="line" id="LC507"> &m_pRenderTarget

="line" id="LC508"> );

="line" id="LC509"> if ( FAILED(hr) )

="line" id="LC510"> {

="line" id="LC511"> SetStatusMessage(L"Couldn't create Direct2D render target!");="line" id="LC512"> return

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

网站地图

Top