Skip to content

Commit

Permalink
Added hand state tracking.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zillode committed Jan 30, 2016
1 parent fe21f93 commit f65860e
Show file tree
Hide file tree
Showing 7 changed files with 180 additions and 60 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ bin
obj
/*.suo
publish
*.suo
5 changes: 3 additions & 2 deletions MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@
</StatusBar>

<CheckBox Grid.Row="2" Content="Show Skeleton" Height="Auto" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="10,11,0,19" x:Name="checkBoxShowSkeleton" Checked="CheckBoxShowSkeletonChanged" Unchecked="CheckBoxShowSkeletonChanged" IsChecked="True"/>
<CheckBox Grid.Row="2" Content="Track Face" Height="Auto" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="123,11,0,19" x:Name="checkBoxTrackFace" Checked="CheckBoxTrackFaceChanged" Unchecked="CheckBoxTrackFaceChanged"/>
<CheckBox Grid.Row="2" Content="Speech Commands" Height="Auto" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="222,11,0,19" x:Name="checkBoxSpeechCommands" Checked="CheckBoxSpeechCommandsChanged" Unchecked="CheckBoxSpeechCommandsChanged"/>
<CheckBox Grid.Row="2" Content="Hands Only" Height="Auto" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="123,11,0,19" x:Name="checkBoxTrackHandsOnly" Checked="CheckBoxTrackHandsOnlyChanged" Unchecked="CheckBoxTrackHandsOnlyChanged"/>
<CheckBox Grid.Row="2" Content="Track Face" Height="Auto" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="220,11,0,19" x:Name="checkBoxTrackFace" Checked="CheckBoxTrackFaceChanged" Unchecked="CheckBoxTrackFaceChanged"/>
<CheckBox Grid.Row="2" Content="Speech Commands" Height="Auto" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="319,11,0,19" x:Name="checkBoxSpeechCommands" Checked="CheckBoxSpeechCommandsChanged" Unchecked="CheckBoxSpeechCommandsChanged"/>
<TextBlock x:Name="helpbox" Margin="0,41,3,10" Width="666" HorizontalAlignment="Right" TextAlignment="Right"><Run Text="Press space to store the gesture in a new file."/></TextBlock>
<ComboBox x:Name="ComboBoxDisplay" HorizontalAlignment="Right" Margin="0,10,3,12" Width="65" HorizontalContentAlignment="Right" VerticalContentAlignment="Stretch" Grid.Row="2" SelectionChanged="ComboBoxDisplaySelectionChanged" SelectedIndex="2">
<ComboBoxItem Content="None"/>
Expand Down
15 changes: 14 additions & 1 deletion MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,7 @@ private void Reader_ColorFrameArrived(object sender, ColorFrameArrivedEventArgs
private void Reader_FrameArrived(object sender, DepthFrameArrivedEventArgs e)
{
bool depthFrameProcessed = false;

if (showMode != showModes.Depth) return;
using (DepthFrame depthFrame = e.FrameReference.AcquireFrame())
{
if (depthFrame != null)
Expand Down Expand Up @@ -1116,6 +1116,7 @@ private void Reader_InfraredFrameArrived(object sender, InfraredFrameArrivedEven
{
if (infraredFrame != null)
{
if (showMode != showModes.IR) return;
// the fastest way to process the infrared frame data is to directly access
// the underlying buffer
using (Microsoft.Kinect.KinectBuffer infraredBuffer = infraredFrame.LockImageBuffer())
Expand Down Expand Up @@ -1208,6 +1209,16 @@ private void CheckBoxSpeechCommandsChanged(object sender, System.Windows.RoutedE
StopSpeechRecognizer();
}

/// <summary>
/// Handles changes to the hands only checkbox
/// </summary>
/// <param name="sender">object sending the event</param>
/// <param name="e">event arguments</param>
private void CheckBoxTrackHandsOnlyChanged(object sender, System.Windows.RoutedEventArgs e)
{
osceleton.SwitchHandsOnly(this.checkBoxTrackHandsOnly.IsChecked.Value);
}

/// <summary>
/// Handles changes to the track face checkbox
/// </summary>
Expand Down Expand Up @@ -1346,6 +1357,8 @@ private void initOSCeleton()
this.depthFrameDescription = this.kinectSensor.DepthFrameSource.FrameDescription;
this.displayDepthWidth = depthFrameDescription.Width;
this.displayDepthHeight = depthFrameDescription.Height;
this.checkBoxTrackHandsOnly.IsChecked = osceleton.GetHandsOnly();
this.checkBoxTrackFace.IsChecked = osceleton.GetFaceTracking();
UpdateObservers();
}

Expand Down
2 changes: 1 addition & 1 deletion OSCeleton-KinectSDK2.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<ProductName>OSCeleton-KinectSDK2</ProductName>
<PublisherName>Zillode</PublisherName>
<OpenBrowserOnPublish>false</OpenBrowserOnPublish>
<ApplicationRevision>4</ApplicationRevision>
<ApplicationRevision>7</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<PublishWizardCompleted>true</PublishWizardCompleted>
Expand Down
37 changes: 31 additions & 6 deletions OSCeleton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ class OSCeleton

// Settings
private bool allUsers = true;
private bool fullBody = true;
private bool handsOnly = true;
private bool faceTracking = false;
private bool writeOSC = true;
private bool writeCSV = true;
private bool writeCSV = false;
private bool useUnixEpochTime = true;
private String oscHost = "127.0.0.1";
private int oscPort = 7110;
Expand All @@ -49,7 +49,7 @@ public void Initialise()
{
args[index] = args[index].ToLower();
if ("allUsers".ToLower().Equals(args[index])) allUsers = StringToBool(args[index + 1]);
if ("fullBody".ToLower().Equals(args[index])) fullBody = StringToBool(args[index + 1]);
if ("handsOnly".ToLower().Equals(args[index])) handsOnly = StringToBool(args[index + 1]);
if ("faceTracking".ToLower().Equals(args[index])) faceTracking = StringToBool(args[index + 1]);
if ("writeOSC".ToLower().Equals(args[index])) writeOSC = StringToBool(args[index + 1]);
if ("writeCSV".ToLower().Equals(args[index])) writeCSV = StringToBool(args[index + 1]);
Expand Down Expand Up @@ -93,6 +93,21 @@ public void Stop()
}
}

public bool GetHandsOnly()
{
return handsOnly;
}

public void SwitchHandsOnly(bool handsOnly)
{
this.handsOnly = handsOnly;
}

public bool GetFaceTracking()
{
return faceTracking;
}

public void OpenNewCSVFile()
{
if (!writeCSV) return;
Expand All @@ -116,6 +131,7 @@ public StreamWriter InitCSVFile()
{
StreamWriter fileWriter = new StreamWriter(Environment.GetFolderPath(Environment.SpecialFolder.Personal) + "/points-MSK2-" + getUnixEpochTime().ToString().Replace(",", ".") + ".csv", false);
fileWriter.WriteLine("Joint, sensor, user, joint, x, y, z, confidence, time");
fileWriter.WriteLine("HandState, sensor, user, joint, x, y, z, confidence, state, stateConfidence, time");
fileWriter.WriteLine("Face, sensor, user, pitch, yaw, roll, time");
fileWriter.WriteLine("FaceProperty, sensor, user, happy, engaged, wearingGlasses, leftEyeClosed, rightEyeClosed, mouthOpen, mouthMoved, lookingAway, time");
return fileWriter;
Expand Down Expand Up @@ -202,7 +218,7 @@ public void EnqueueBody(int sensorId, int user, Body b)
{
if (!capturing) { return; }
if (b == null) { return; }
trackingInformationQueue.Add(new BodyTrackingInformation(sensorId, user, b, fullBody, getTime()));
trackingInformationQueue.Add(new BodyTrackingInformation(sensorId, user, b, handsOnly, getTime()));
}

float detectionResultToConfidence(DetectionResult r)
Expand Down Expand Up @@ -258,9 +274,18 @@ void SendTrackingInformation()
{
TrackingInformation i = trackingInformationQueue.Take();
if (i != null && capturing)
lock (fileWriter)
{
i.Send(osc, fileWriter, pointScale);
if (fileWriter != null)
{
lock (fileWriter)
{
i.Send(pointScale, osc, fileWriter);
}
}
else
{
i.Send(pointScale, osc, fileWriter);
}
}
}
}
Expand Down
32 changes: 25 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ OSCeleton-KinectSDK2
What is this?
-------------

As the title says, it's just a small program that takes kinect
As the title says, it's just a small program that takes Kinect
skeleton data from the KinectSDK (v2) framework and spits out the coordinates
of the skeleton's joints via OSC messages. These can can then be used
on your language / framework of choice.
Expand Down Expand Up @@ -40,11 +40,29 @@ The messages will have the following format:
s: Joint name, check out the full list of joints below
i: The ID of the sensor
i: The ID of the user
f: X coordinate of joint in real world coordinates (centimers)
f: Y coordinate of joint in real world coordinates (centimers)
f: Z coordinate of joint in real world coordinates (centimers)
f: X coordinate of joint in real world coordinates (centimetres)
f: Y coordinate of joint in real world coordinates (centimetres)
f: Z coordinate of joint in real world coordinates (centimetres)
f: confidence value in interval [0.0, 1.0]
d: timestamp in milliseconds since Unix epoch
d: time stamp in milliseconds since Unix epoch

Note: the Y coordinate is inverted compared to the default KinectSDK to be compatible with OpenNI.

### Hand message - message with the coordinates of each hand:
The messages will have the following format:

Address pattern: "/osceleton2/hand"
Type tag: "iiiffffifd"
i: The ID of the sensor
i: The ID of the user
i: The ID of the hand (1 == Left, 2 == Right)
f: X coordinate of joint in real world coordinates (centimetres)
f: Y coordinate of joint in real world coordinates (centimetres)
f: Z coordinate of joint in real world coordinates (centimetres)
f: confidence value in interval [0.0, 1.0]
i: state of the hand (1 == Open, 2 == Closed, 3 == Lasso, 4 == Unknown, 5 == NotTracked)
f: confidence value of the hand state in interval [0.0, 1.0]
d: time stamp in milliseconds since Unix epoch

Note: the Y coordinate is inverted compared to the default KinectSDK to be compatible with OpenNI.

Expand All @@ -58,7 +76,7 @@ The messages will have the following format:
f: pitch of the head [-90, 90]
f: yaw of the head [-90, 90]
f: roll of the head [-90, 90]
d: timestamp in milliseconds since Unix epoch
d: time stamp in milliseconds since Unix epoch

Further information about the FaceRotation properties can be found [here](https://msdn.microsoft.com/en-us/library/microsoft.kinect.face.faceframeresult.facerotationquaternion.aspx)

Expand All @@ -77,7 +95,7 @@ The messages will have the following format:
f: mouth open [0, 1]
f: mouth moved [0, 1]
f: looking away [0, 1]
d: timestamp in milliseconds since Unix epoch
d: time stamp in milliseconds since Unix epoch

Further information about the Face properties can be found [here](https://msdn.microsoft.com/en-us/library/microsoft.kinect.face.faceproperty.aspx)

Expand Down
Loading

0 comments on commit f65860e

Please sign in to comment.