Added the option to only stream the body data (skeleton and body point cloud) instead of everything.

This commit is contained in:
marek
2015-11-06 18:48:15 +01:00
parent 948eee769e
commit ef1c5ac2ce
10 changed files with 116 additions and 40 deletions
+8 -1
View File
@@ -33,8 +33,10 @@ namespace KinectServer
public BindingList<MarkerPose> lMarkerPoses = new BindingList<MarkerPose>(); public BindingList<MarkerPose> lMarkerPoses = new BindingList<MarkerPose>();
public bool bStreamOnlyBodies = false;
public int nNumICPIterations = 10; public int nNumICPIterations = 10;
public int nMaxNumRefineIters = 10; public int nNumRefineIters = 2;
public bool bMergeScansForSave = false; public bool bMergeScansForSave = false;
public KinectSettings() public KinectSettings()
@@ -87,6 +89,11 @@ namespace KinectServer
lData.AddRange(bTemp); lData.AddRange(bTemp);
} }
if (bStreamOnlyBodies)
lData.Add(1);
else
lData.Add(0);
return lData; return lData;
} }
} }
+3 -23
View File
@@ -316,16 +316,9 @@ namespace KinectServer
//Use ICP to refine the sensor poses. //Use ICP to refine the sensor poses.
//This part is explained in more detail in our article (name on top of this file). //This part is explained in more detail in our article (name on top of this file).
float error = 1;
float oldError = 1;
bool firstPass = true;
int iter = 0;
while (true)
{
if (iter > oSettings.nMaxNumRefineIters)
break;
error = 0; for (int refineIter = 0; refineIter < oSettings.nNumRefineIters; refineIter++)
{
for (int i = 0; i < lAllFrameVertices.Count; i++) for (int i = 0; i < lAllFrameVertices.Count; i++)
{ {
List<float> otherFramesVertices = new List<float>(); List<float> otherFramesVertices = new List<float>();
@@ -345,25 +338,12 @@ namespace KinectServer
Marshal.Copy(verts1, 0, pVerts1, verts1.Length); Marshal.Copy(verts1, 0, pVerts1, verts1.Length);
Marshal.Copy(verts2, 0, pVerts2, verts2.Length); Marshal.Copy(verts2, 0, pVerts2, verts2.Length);
error += ICP(pVerts1, pVerts2, otherFramesVertices.Count / 3, lAllFrameVertices[i].Count / 3, Rs[i], Ts[i], oSettings.nNumICPIterations); ICP(pVerts1, pVerts2, otherFramesVertices.Count / 3, lAllFrameVertices[i].Count / 3, Rs[i], Ts[i], oSettings.nNumICPIterations);
Marshal.Copy(pVerts2, verts2, 0, verts2.Length); Marshal.Copy(pVerts2, verts2, 0, verts2.Length);
lAllFrameVertices[i].Clear(); lAllFrameVertices[i].Clear();
lAllFrameVertices[i].AddRange(verts2); lAllFrameVertices[i].AddRange(verts2);
} }
if (firstPass)
{
firstPass = false;
}
else
{
if (Math.Abs(oldError - error) / error < 0.01)
break;
}
oldError = error;
iter++;
} }
//Update the calibration data in client machines. //Update the calibration data in client machines.
+50 -9
View File
@@ -71,11 +71,15 @@
this.grServer = new System.Windows.Forms.GroupBox(); this.grServer = new System.Windows.Forms.GroupBox();
this.txtRefinIters = new System.Windows.Forms.TextBox(); this.txtRefinIters = new System.Windows.Forms.TextBox();
this.lbOuterIters = new System.Windows.Forms.Label(); this.lbOuterIters = new System.Windows.Forms.Label();
this.grBody = new System.Windows.Forms.GroupBox();
this.chBodyData = new System.Windows.Forms.CheckBox();
this.label1 = new System.Windows.Forms.Label();
this.grClient.SuspendLayout(); this.grClient.SuspendLayout();
this.grMarkers.SuspendLayout(); this.grMarkers.SuspendLayout();
this.grBounding.SuspendLayout(); this.grBounding.SuspendLayout();
this.grFiltering.SuspendLayout(); this.grFiltering.SuspendLayout();
this.grServer.SuspendLayout(); this.grServer.SuspendLayout();
this.grBody.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
// //
// lbMerge // lbMerge
@@ -90,7 +94,7 @@
// chMerge // chMerge
// //
this.chMerge.AutoSize = true; this.chMerge.AutoSize = true;
this.chMerge.Location = new System.Drawing.Point(91, 48); this.chMerge.Location = new System.Drawing.Point(98, 48);
this.chMerge.Name = "chMerge"; this.chMerge.Name = "chMerge";
this.chMerge.Size = new System.Drawing.Size(86, 17); this.chMerge.Size = new System.Drawing.Size(86, 17);
this.chMerge.TabIndex = 23; this.chMerge.TabIndex = 23;
@@ -109,7 +113,7 @@
// //
// txtICPIters // txtICPIters
// //
this.txtICPIters.Location = new System.Drawing.Point(91, 23); this.txtICPIters.Location = new System.Drawing.Point(98, 23);
this.txtICPIters.Name = "txtICPIters"; this.txtICPIters.Name = "txtICPIters";
this.txtICPIters.Size = new System.Drawing.Size(38, 20); this.txtICPIters.Size = new System.Drawing.Size(38, 20);
this.txtICPIters.TabIndex = 25; this.txtICPIters.TabIndex = 25;
@@ -117,12 +121,13 @@
// //
// grClient // grClient
// //
this.grClient.Controls.Add(this.grBody);
this.grClient.Controls.Add(this.grMarkers); this.grClient.Controls.Add(this.grMarkers);
this.grClient.Controls.Add(this.grBounding); this.grClient.Controls.Add(this.grBounding);
this.grClient.Controls.Add(this.grFiltering); this.grClient.Controls.Add(this.grFiltering);
this.grClient.Location = new System.Drawing.Point(12, 12); this.grClient.Location = new System.Drawing.Point(12, 12);
this.grClient.Name = "grClient"; this.grClient.Name = "grClient";
this.grClient.Size = new System.Drawing.Size(632, 212); this.grClient.Size = new System.Drawing.Size(632, 327);
this.grClient.TabIndex = 43; this.grClient.TabIndex = 43;
this.grClient.TabStop = false; this.grClient.TabStop = false;
this.grClient.Text = "KinectClient settings"; this.grClient.Text = "KinectClient settings";
@@ -471,7 +476,7 @@
this.grServer.Controls.Add(this.txtICPIters); this.grServer.Controls.Add(this.txtICPIters);
this.grServer.Controls.Add(this.chMerge); this.grServer.Controls.Add(this.chMerge);
this.grServer.Controls.Add(this.lbICPIters); this.grServer.Controls.Add(this.lbICPIters);
this.grServer.Location = new System.Drawing.Point(12, 230); this.grServer.Location = new System.Drawing.Point(12, 345);
this.grServer.Name = "grServer"; this.grServer.Name = "grServer";
this.grServer.Size = new System.Drawing.Size(632, 78); this.grServer.Size = new System.Drawing.Size(632, 78);
this.grServer.TabIndex = 44; this.grServer.TabIndex = 44;
@@ -480,7 +485,7 @@
// //
// txtRefinIters // txtRefinIters
// //
this.txtRefinIters.Location = new System.Drawing.Point(271, 23); this.txtRefinIters.Location = new System.Drawing.Point(266, 23);
this.txtRefinIters.Name = "txtRefinIters"; this.txtRefinIters.Name = "txtRefinIters";
this.txtRefinIters.Size = new System.Drawing.Size(38, 20); this.txtRefinIters.Size = new System.Drawing.Size(38, 20);
this.txtRefinIters.TabIndex = 27; this.txtRefinIters.TabIndex = 27;
@@ -489,17 +494,48 @@
// lbOuterIters // lbOuterIters
// //
this.lbOuterIters.AutoSize = true; this.lbOuterIters.AutoSize = true;
this.lbOuterIters.Location = new System.Drawing.Point(135, 26); this.lbOuterIters.Location = new System.Drawing.Point(142, 26);
this.lbOuterIters.Name = "lbOuterIters"; this.lbOuterIters.Name = "lbOuterIters";
this.lbOuterIters.Size = new System.Drawing.Size(139, 13); this.lbOuterIters.Size = new System.Drawing.Size(118, 13);
this.lbOuterIters.TabIndex = 26; this.lbOuterIters.TabIndex = 26;
this.lbOuterIters.Text = "Max num of refinement iters:"; this.lbOuterIters.Text = "Num of refinement iters:";
//
// grBody
//
this.grBody.Controls.Add(this.label1);
this.grBody.Controls.Add(this.chBodyData);
this.grBody.Location = new System.Drawing.Point(9, 211);
this.grBody.Name = "grBody";
this.grBody.Size = new System.Drawing.Size(249, 110);
this.grBody.TabIndex = 47;
this.grBody.TabStop = false;
this.grBody.Text = "Body data";
//
// chBodyData
//
this.chBodyData.AutoSize = true;
this.chBodyData.Location = new System.Drawing.Point(11, 19);
this.chBodyData.Name = "chBodyData";
this.chBodyData.Size = new System.Drawing.Size(113, 17);
this.chBodyData.TabIndex = 19;
this.chBodyData.Text = "stream only bodies";
this.chBodyData.UseVisualStyleBackColor = true;
this.chBodyData.CheckedChanged += new System.EventHandler(this.chBodyData_CheckedChanged);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(11, 43);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(187, 13);
this.label1.TabIndex = 20;
this.label1.Text = "More features will be added here soon";
// //
// SettingsForm // SettingsForm
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(656, 319); this.ClientSize = new System.Drawing.Size(656, 435);
this.Controls.Add(this.grServer); this.Controls.Add(this.grServer);
this.Controls.Add(this.grClient); this.Controls.Add(this.grClient);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
@@ -516,6 +552,8 @@
this.grFiltering.PerformLayout(); this.grFiltering.PerformLayout();
this.grServer.ResumeLayout(false); this.grServer.ResumeLayout(false);
this.grServer.PerformLayout(); this.grServer.PerformLayout();
this.grBody.ResumeLayout(false);
this.grBody.PerformLayout();
this.ResumeLayout(false); this.ResumeLayout(false);
} }
@@ -565,6 +603,9 @@
private System.Windows.Forms.Label lbZ; private System.Windows.Forms.Label lbZ;
private System.Windows.Forms.Label lbY; private System.Windows.Forms.Label lbY;
private System.Windows.Forms.Label lbX; private System.Windows.Forms.Label lbX;
private System.Windows.Forms.GroupBox grBody;
private System.Windows.Forms.CheckBox chBodyData;
private System.Windows.Forms.Label label1;
} }
} }
+9 -2
View File
@@ -51,10 +51,11 @@ namespace KinectServer
lisMarkers.DataSource = oSettings.lMarkerPoses; lisMarkers.DataSource = oSettings.lMarkerPoses;
chBodyData.Checked = oSettings.bStreamOnlyBodies;
chMerge.Checked = oSettings.bMergeScansForSave; chMerge.Checked = oSettings.bMergeScansForSave;
txtICPIters.Text = oSettings.nNumICPIterations.ToString(); txtICPIters.Text = oSettings.nNumICPIterations.ToString();
txtRefinIters.Text = oSettings.nMaxNumRefineIters.ToString(); txtRefinIters.Text = oSettings.nNumRefineIters.ToString();
} }
void UpdateClients() void UpdateClients()
@@ -156,7 +157,7 @@ namespace KinectServer
private void txtRefinIters_TextChanged(object sender, EventArgs e) private void txtRefinIters_TextChanged(object sender, EventArgs e)
{ {
Int32.TryParse(txtRefinIters.Text, out oSettings.nMaxNumRefineIters); Int32.TryParse(txtRefinIters.Text, out oSettings.nNumRefineIters);
} }
private void chMerge_CheckedChanged(object sender, EventArgs e) private void chMerge_CheckedChanged(object sender, EventArgs e)
@@ -281,5 +282,11 @@ namespace KinectServer
UpdateClients(); UpdateClients();
} }
} }
private void chBodyData_CheckedChanged(object sender, EventArgs e)
{
oSettings.bStreamOnlyBodies = chBodyData.Checked;
UpdateClients();
}
} }
} }
+1
View File
@@ -43,6 +43,7 @@ public:
int nDepthFrameHeight, nDepthFrameWidth; int nDepthFrameHeight, nDepthFrameWidth;
UINT16 *pDepth; UINT16 *pDepth;
BYTE *pBodyIndex;
RGB *pColorRGBX; RGB *pColorRGBX;
std::vector<Body> vBodies; std::vector<Body> vBodies;
}; };
+1
View File
@@ -39,4 +39,5 @@ private:
void GetDepthFrame(IMultiSourceFrame* pMultiFrame); void GetDepthFrame(IMultiSourceFrame* pMultiFrame);
void GetColorFrame(IMultiSourceFrame* pMultiFrame); void GetColorFrame(IMultiSourceFrame* pMultiFrame);
void GetBodyFrame(IMultiSourceFrame* pMultiFrame); void GetBodyFrame(IMultiSourceFrame* pMultiFrame);
void GetBodyIndexFrame(IMultiSourceFrame* pMultiFrame);
}; };
+2 -1
View File
@@ -40,6 +40,7 @@ private:
bool m_bCalibrate; bool m_bCalibrate;
bool m_bFilter; bool m_bFilter;
bool m_bStreamOnlyBodies;
ICapture *pCapture; ICapture *pCapture;
@@ -86,7 +87,7 @@ private:
void SendFrame(vector<Point3f> vertices, vector<RGB> RGB, vector<Body> body); void SendFrame(vector<Point3f> vertices, vector<RGB> RGB, vector<Body> body);
void SocketThreadFunction(); void SocketThreadFunction();
void StoreFrame(Point3f *vertices, Point2f *mapping, RGB *color, vector<Body> &bodies); void StoreFrame(Point3f *vertices, Point2f *mapping, RGB *color, vector<Body> &bodies, BYTE* bodyIndex);
void ShowFPS(); void ShowFPS();
void ReadIPFromFile(); void ReadIPFromFile();
void WriteIPToFile(); void WriteIPToFile();
+7
View File
@@ -25,6 +25,7 @@ ICapture::ICapture()
pDepth = NULL; pDepth = NULL;
pColorRGBX = NULL; pColorRGBX = NULL;
pBodyIndex = NULL;
} }
ICapture::~ICapture() ICapture::~ICapture()
@@ -40,4 +41,10 @@ ICapture::~ICapture()
delete[] pColorRGBX; delete[] pColorRGBX;
pColorRGBX = NULL; pColorRGBX = NULL;
} }
if (pBodyIndex != NULL)
{
delete[] pBodyIndex;
pBodyIndex = NULL;
}
} }
+24
View File
@@ -97,6 +97,7 @@ bool KinectCapture::AcquireFrame()
GetDepthFrame(pMultiFrame); GetDepthFrame(pMultiFrame);
GetColorFrame(pMultiFrame); GetColorFrame(pMultiFrame);
GetBodyFrame(pMultiFrame); GetBodyFrame(pMultiFrame);
GetBodyIndexFrame(pMultiFrame);
return true; return true;
@@ -218,3 +219,26 @@ void KinectCapture::GetBodyFrame(IMultiSourceFrame* pMultiFrame)
SafeRelease(pBodyFrame); SafeRelease(pBodyFrame);
SafeRelease(pBodyFrameReference); SafeRelease(pBodyFrameReference);
} }
void KinectCapture::GetBodyIndexFrame(IMultiSourceFrame* pMultiFrame)
{
IBodyIndexFrameReference* pBodyIndexFrameReference = NULL;
IBodyIndexFrame* pBodyIndexFrame = NULL;
pMultiFrame->get_BodyIndexFrameReference(&pBodyIndexFrameReference);
HRESULT hr = pBodyIndexFrameReference->AcquireFrame(&pBodyIndexFrame);
if (SUCCEEDED(hr))
{
if (pBodyIndex == NULL)
{
pBodyIndex = new BYTE[nDepthFrameHeight * nDepthFrameWidth];
}
UINT nBufferSize = nDepthFrameHeight * nDepthFrameWidth;
hr = pBodyIndexFrame->CopyFrameDataToArray(nBufferSize, pBodyIndex);
}
SafeRelease(pBodyIndexFrame);
SafeRelease(pBodyIndexFrameReference);
}
+9 -2
View File
@@ -50,6 +50,7 @@ LiveScanClient::LiveScanClient() :
m_pDepthCoordinatesOfColor(NULL), m_pDepthCoordinatesOfColor(NULL),
m_bCalibrate(false), m_bCalibrate(false),
m_bFilter(false), m_bFilter(false),
m_bStreamOnlyBodies(false),
m_bCaptureFrame(false), m_bCaptureFrame(false),
m_bConnected(false), m_bConnected(false),
m_bConfirmCaptured(false), m_bConfirmCaptured(false),
@@ -195,7 +196,7 @@ void LiveScanClient::UpdateFrame()
pCapture->MapDepthFrameToColorSpace(m_pColorCoordinatesOfDepth); pCapture->MapDepthFrameToColorSpace(m_pColorCoordinatesOfDepth);
{ {
std::lock_guard<std::mutex> lock(m_mSocketThreadMutex); std::lock_guard<std::mutex> lock(m_mSocketThreadMutex);
StoreFrame(m_pCameraSpaceCoordinates, m_pColorCoordinatesOfDepth, pCapture->pColorRGBX, pCapture->vBodies); StoreFrame(m_pCameraSpaceCoordinates, m_pColorCoordinatesOfDepth, pCapture->pColorRGBX, pCapture->vBodies, pCapture->pBodyIndex);
if (m_bCaptureFrame) if (m_bCaptureFrame)
{ {
@@ -497,6 +498,9 @@ void LiveScanClient::HandleSocket()
i += sizeof(int); i += sizeof(int);
} }
m_bStreamOnlyBodies = (received[i] != 0);
i++;
//so that we do not lose the next character in the stream //so that we do not lose the next character in the stream
i--; i--;
} }
@@ -683,7 +687,7 @@ void LiveScanClient::SendFrame(vector<Point3f> vertices, vector<RGB> RGB, vector
} }
void LiveScanClient::StoreFrame(Point3f *vertices, Point2f *mapping, RGB *color, vector<Body> &bodies) void LiveScanClient::StoreFrame(Point3f *vertices, Point2f *mapping, RGB *color, vector<Body> &bodies, BYTE* bodyIndex)
{ {
std::vector<Point3f> goodVertices; std::vector<Point3f> goodVertices;
std::vector<RGB> goodColorPoints; std::vector<RGB> goodColorPoints;
@@ -692,6 +696,9 @@ void LiveScanClient::StoreFrame(Point3f *vertices, Point2f *mapping, RGB *color,
for (unsigned int vertexIndex = 0; vertexIndex < nVertices; vertexIndex++) for (unsigned int vertexIndex = 0; vertexIndex < nVertices; vertexIndex++)
{ {
if (m_bStreamOnlyBodies && bodyIndex[vertexIndex] >= bodies.size())
continue;
if (vertices[vertexIndex].Z >= 0 && mapping[vertexIndex].Y >= 0 && mapping[vertexIndex].Y < pCapture->nColorFrameHeight) if (vertices[vertexIndex].Z >= 0 && mapping[vertexIndex].Y >= 0 && mapping[vertexIndex].Y < pCapture->nColorFrameHeight)
{ {
Point3f temp = vertices[vertexIndex]; Point3f temp = vertices[vertexIndex];