Commit 9ca31f20 authored by Alexander Krause's avatar Alexander Krause

new way to handle only the first tracked body

parent b5b0bfc9
......@@ -29,8 +29,10 @@ namespace ExplorVizGestureControl
private Body[] bodies;
private BodyFrameReader bodyReader;
private ulong bodyTrackingID = 0;
private int bodyIndex;
private ContinuousGestureDetector continuousGestureDetector;
private ContinuousGestureDetector continuousGestureDetector;
private DiscreteGestureDetector discreteGestureDetector;
private KinectJointFilter filter = new KinectJointFilter();
......@@ -50,7 +52,7 @@ namespace ExplorVizGestureControl
public MainWindow()
{
InitializeComponent();
InitializeComponent();
// Connect to Kinect
kinect = null;
......@@ -66,12 +68,12 @@ namespace ExplorVizGestureControl
// XAML element
FrameworkElement xamlElement = new FrameworkElement();
xamlElement.Style = (Style)this.FindResource("Stream");
xamlElement.Style = (Style)this.FindResource("Stream");
continuousGestureDetector = new ContinuousGestureDetector();
continuousGestureDetector = new ContinuousGestureDetector();
discreteGestureDetector = new DiscreteGestureDetector(continuousGestureDetector);
filter.Init();
colorStream = new ColorStream(kinect, kinect.ColorFrameSource.OpenReader());
bodyStream = new BodyDrawing(kinect, xamlElement.Width, xamlElement.Height);
jointAccumulator = new JointAccumulator();
......@@ -90,14 +92,14 @@ namespace ExplorVizGestureControl
{
Show();
WindowState = WindowState.Normal;
};
};
}
#endregion
#region Main Loop
#region Main Loop
private void OnBodyFrameArrived(object sender, BodyFrameArrivedEventArgs e)
{
......@@ -114,10 +116,13 @@ namespace ExplorVizGestureControl
frame.GetAndRefreshBodyData(bodies);
// Loop all bodies
foreach (Body body in bodies)
int length = bodies.Length;
for (int i = 0; i < length; i++)
{
// Only process tracked bodies
if (body.IsTracked && nearestBody(body, bodies))
Body body = bodies[i];
// Only process the first tracked body
if (body.IsTracked && isFirstTrackedBody(body, i))
{
filter.UpdateFilter(body);
CameraSpacePoint[] filteredJoints = filter.GetFilteredJoints();
......@@ -143,42 +148,41 @@ namespace ExplorVizGestureControl
}
#endregion
#region Helper
private bool nearestBody(Body possibleNearest, Body[] bodies)
private bool isFirstTrackedBody(Body body, int index)
{
JointType spineBase = JointType.SpineBase;
float possibleBodyZ = possibleNearest.Joints[spineBase].Position.Z;
foreach (Body body in bodies)
if (bodyTrackingID == 0)
{
if (body.IsTracked)
{
float spineBaseZ = body.Joints[spineBase].Position.Z;
if (!body.Equals(possibleNearest) && possibleBodyZ > spineBaseZ)
{
return false;
}
}
bodyTrackingID = body.TrackingId;
bodyIndex = index;
}
return true;
return bodyTrackingID == body.TrackingId ? true : false;
}
private bool AnyBodyTracked()
{
return bodies[0].IsTracked || bodies[1].IsTracked || bodies[2].IsTracked
&& bodies[3].IsTracked || bodies[4].IsTracked || bodies[5].IsTracked ? true : false;
if (bodies[bodyIndex].IsTracked)
{
return true;
}
else
{
bodyTrackingID = 0;
return false;
}
}
private void CleanupOnExit(object sender, CancelEventArgs e)
{
{
if (colorStream.CFReader != null)
{
colorStream.CFReader.Dispose();
colorStream.CFReader = null;
}
}
if (bodyReader != null)
{
......@@ -197,7 +201,7 @@ namespace ExplorVizGestureControl
}
protected override void OnStateChanged(EventArgs e)
{
{
if (WindowState == System.Windows.WindowState.Minimized)
this.Hide();
......@@ -206,7 +210,7 @@ namespace ExplorVizGestureControl
#endregion
#region Listener
private void BodyStream_Clicked(object sender, RoutedEventArgs e)
......@@ -221,16 +225,16 @@ namespace ExplorVizGestureControl
}
private void OnKeyDownHandler(object sender, KeyEventArgs e)
{
{
if (e.Key == Key.Return)
{
TextBox textBox = sender as TextBox;
continuousGestureDetector.updateDynamicValues(textBox.Name, Convert.ToDouble(textBox.Text));
continuousGestureDetector.updateDynamicValues(textBox.Name, Convert.ToDouble(textBox.Text));
}
}
#endregion
#region Getters
public ImageSource JointsSource
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment