Working with Azure Kinect but without body and only single sensor per machine

This commit is contained in:
Marek Kowalski
2019-08-16 17:27:03 +01:00
parent 987aa32b70
commit f49bcaf5d9
15 changed files with 524 additions and 523 deletions
+97 -97
View File
@@ -10,12 +10,12 @@
/// <summary>
/// Constructor
/// </summary>
ImageRenderer::ImageRenderer() :
ImageRenderer::ImageRenderer() :
m_hWnd(0),
m_sourceWidth(0),
m_sourceHeight(0),
m_sourceStride(0),
m_pD2DFactory(NULL),
m_pD2DFactory(NULL),
m_pRenderTarget(NULL),
m_pBitmap(0)
{
@@ -70,9 +70,9 @@ HRESULT ImageRenderer::EnsureResources()
// Create a bitmap that we can copy image data into and then render to the target
hr = m_pRenderTarget->CreateBitmap(
size,
size,
D2D1::BitmapProperties(D2D1::PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_IGNORE)),
&m_pBitmap
&m_pBitmap
);
if (FAILED(hr))
@@ -86,7 +86,7 @@ HRESULT ImageRenderer::EnsureResources()
}
/// <summary>
/// Dispose of Direct2d resources
/// Dispose of Direct2d resources
/// </summary>
void ImageRenderer::DiscardResources()
{
@@ -149,7 +149,7 @@ HRESULT ImageRenderer::Draw(BYTE* pImage, unsigned long cbImage, std::vector<Bod
{
return hr;
}
// Copy the image that was passed in into the direct2d bitmap
hr = m_pBitmap->CopyFromMemory(NULL, pImage, m_sourceStride);
@@ -157,17 +157,17 @@ HRESULT ImageRenderer::Draw(BYTE* pImage, unsigned long cbImage, std::vector<Bod
{
return hr;
}
m_pRenderTarget->BeginDraw();
// Draw the bitmap stretched to the size of the window
m_pRenderTarget->DrawBitmap(m_pBitmap);
for (unsigned int i = 0; i < vBodies.size(); i++)
{
if (vBodies[i].bTracked)
{
DrawBody(vBodies[i]);
//DrawBody(vBodies[i]);
}
}
@@ -188,62 +188,62 @@ HRESULT ImageRenderer::Draw(BYTE* pImage, unsigned long cbImage, std::vector<Bod
/// Draws all the body to the associated hwnd, assumes that BeginDraw has been called
/// </summary>
/// <param name="body">body to be drawn</param>
void ImageRenderer::DrawBody(Body &body)
{
// Draw the bones
// Torso
DrawBone(body, JointType_Head, JointType_Neck);
DrawBone(body, JointType_Neck, JointType_SpineShoulder);
DrawBone(body, JointType_SpineShoulder, JointType_SpineMid);
DrawBone(body, JointType_SpineMid, JointType_SpineBase);
DrawBone(body, JointType_SpineShoulder, JointType_ShoulderRight);
DrawBone(body, JointType_SpineShoulder, JointType_ShoulderLeft);
DrawBone(body, JointType_SpineBase, JointType_HipRight);
DrawBone(body, JointType_SpineBase, JointType_HipLeft);
// Right Arm
DrawBone(body, JointType_ShoulderRight, JointType_ElbowRight);
DrawBone(body, JointType_ElbowRight, JointType_WristRight);
DrawBone(body, JointType_WristRight, JointType_HandRight);
DrawBone(body, JointType_HandRight, JointType_HandTipRight);
DrawBone(body, JointType_WristRight, JointType_ThumbRight);
// Left Arm
DrawBone(body, JointType_ShoulderLeft, JointType_ElbowLeft);
DrawBone(body, JointType_ElbowLeft, JointType_WristLeft);
DrawBone(body, JointType_WristLeft, JointType_HandLeft);
DrawBone(body, JointType_HandLeft, JointType_HandTipLeft);
DrawBone(body, JointType_WristLeft, JointType_ThumbLeft);
// Right Leg
DrawBone(body, JointType_HipRight, JointType_KneeRight);
DrawBone(body, JointType_KneeRight, JointType_AnkleRight);
DrawBone(body, JointType_AnkleRight, JointType_FootRight);
// Left Leg
DrawBone(body, JointType_HipLeft, JointType_KneeLeft);
DrawBone(body, JointType_KneeLeft, JointType_AnkleLeft);
DrawBone(body, JointType_AnkleLeft, JointType_FootLeft);
for (unsigned int i = 0; i < body.vJoints.size(); i++)
{
D2D1_POINT_2F tempPoint;
tempPoint.x = body.vJointsInColorSpace[i].X;
tempPoint.y = body.vJointsInColorSpace[i].Y;
D2D1_ELLIPSE ellipse = D2D1::Ellipse(tempPoint, 6.0f, 6.0f);
if (body.vJoints[i].TrackingState == TrackingState_Inferred)
{
m_pRenderTarget->FillEllipse(ellipse, m_pBrushJointInferred);
}
else if (body.vJoints[i].TrackingState == TrackingState_Tracked)
{
m_pRenderTarget->FillEllipse(ellipse, m_pBrushJointTracked);
}
}
}
//void ImageRenderer::DrawBody(Body &body)
//{
// // Draw the bones
//
// // Torso
// DrawBone(body, JointType_Head, JointType_Neck);
// DrawBone(body, JointType_Neck, JointType_SpineShoulder);
// DrawBone(body, JointType_SpineShoulder, JointType_SpineMid);
// DrawBone(body, JointType_SpineMid, JointType_SpineBase);
// DrawBone(body, JointType_SpineShoulder, JointType_ShoulderRight);
// DrawBone(body, JointType_SpineShoulder, JointType_ShoulderLeft);
// DrawBone(body, JointType_SpineBase, JointType_HipRight);
// DrawBone(body, JointType_SpineBase, JointType_HipLeft);
//
// // Right Arm
// DrawBone(body, JointType_ShoulderRight, JointType_ElbowRight);
// DrawBone(body, JointType_ElbowRight, JointType_WristRight);
// DrawBone(body, JointType_WristRight, JointType_HandRight);
// DrawBone(body, JointType_HandRight, JointType_HandTipRight);
// DrawBone(body, JointType_WristRight, JointType_ThumbRight);
//
// // Left Arm
// DrawBone(body, JointType_ShoulderLeft, JointType_ElbowLeft);
// DrawBone(body, JointType_ElbowLeft, JointType_WristLeft);
// DrawBone(body, JointType_WristLeft, JointType_HandLeft);
// DrawBone(body, JointType_HandLeft, JointType_HandTipLeft);
// DrawBone(body, JointType_WristLeft, JointType_ThumbLeft);
//
// // Right Leg
// DrawBone(body, JointType_HipRight, JointType_KneeRight);
// DrawBone(body, JointType_KneeRight, JointType_AnkleRight);
// DrawBone(body, JointType_AnkleRight, JointType_FootRight);
//
// // Left Leg
// DrawBone(body, JointType_HipLeft, JointType_KneeLeft);
// DrawBone(body, JointType_KneeLeft, JointType_AnkleLeft);
// DrawBone(body, JointType_AnkleLeft, JointType_FootLeft);
//
// for (unsigned int i = 0; i < body.vJoints.size(); i++)
// {
// D2D1_POINT_2F tempPoint;
// tempPoint.x = body.vJointsInColorSpace[i].X;
// tempPoint.y = body.vJointsInColorSpace[i].Y;
//
// D2D1_ELLIPSE ellipse = D2D1::Ellipse(tempPoint, 6.0f, 6.0f);
//
// if (body.vJoints[i].TrackingState == TrackingState_Inferred)
// {
// m_pRenderTarget->FillEllipse(ellipse, m_pBrushJointInferred);
// }
// else if (body.vJoints[i].TrackingState == TrackingState_Tracked)
// {
// m_pRenderTarget->FillEllipse(ellipse, m_pBrushJointTracked);
// }
// }
//}
/// <summary>
/// Draws one bone of a body (joint to joint)
@@ -251,35 +251,35 @@ void ImageRenderer::DrawBody(Body &body)
/// <param name="body">body to be drawn</param>
/// <param name="joint0">one joint of the bone to draw</param>
/// <param name="joint1">other joint of the bone to draw</param>
void ImageRenderer::DrawBone(Body &body, JointType joint0, JointType joint1)
{
TrackingState joint0State = body.vJoints[joint0].TrackingState;
TrackingState joint1State = body.vJoints[joint1].TrackingState;
// If we can't find either of these joints, exit
if ((joint0State == TrackingState_NotTracked) || (joint1State == TrackingState_NotTracked))
{
return;
}
// Don't draw if both points are inferred
if ((joint0State == TrackingState_Inferred) && (joint1State == TrackingState_Inferred))
{
return;
}
D2D1_POINT_2F joint0Point, joint1Point;
joint0Point.x = body.vJointsInColorSpace[joint0].X;
joint0Point.y = body.vJointsInColorSpace[joint0].Y;
joint1Point.x = body.vJointsInColorSpace[joint1].X;
joint1Point.y = body.vJointsInColorSpace[joint1].Y;
// We assume all drawn bones are inferred unless BOTH joints are tracked
if ((joint0State == TrackingState_Tracked) && (joint1State == TrackingState_Tracked))
{
m_pRenderTarget->DrawLine(joint0Point, joint1Point, m_pBrushBoneTracked, 10.0f);
}
else
{
m_pRenderTarget->DrawLine(joint0Point, joint1Point, m_pBrushBoneInferred, 3);
}
}
//void ImageRenderer::DrawBone(Body &body, JointType joint0, JointType joint1)
//{
// TrackingState joint0State = body.vJoints[joint0].TrackingState;
// TrackingState joint1State = body.vJoints[joint1].TrackingState;
//
// // If we can't find either of these joints, exit
// if ((joint0State == TrackingState_NotTracked) || (joint1State == TrackingState_NotTracked))
// {
// return;
// }
//
// // Don't draw if both points are inferred
// if ((joint0State == TrackingState_Inferred) && (joint1State == TrackingState_Inferred))
// {
// return;
// }
//
// D2D1_POINT_2F joint0Point, joint1Point;
// joint0Point.x = body.vJointsInColorSpace[joint0].X;
// joint0Point.y = body.vJointsInColorSpace[joint0].Y;
// joint1Point.x = body.vJointsInColorSpace[joint1].X;
// joint1Point.y = body.vJointsInColorSpace[joint1].Y;
// // We assume all drawn bones are inferred unless BOTH joints are tracked
// if ((joint0State == TrackingState_Tracked) && (joint1State == TrackingState_Tracked))
// {
// m_pRenderTarget->DrawLine(joint0Point, joint1Point, m_pBrushBoneTracked, 10.0f);
// }
// else
// {
// m_pRenderTarget->DrawLine(joint0Point, joint1Point, m_pBrushBoneInferred, 3);
// }
//}