Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added joint orientation tracking.

  • Loading branch information...
commit fdf08b6018441d4b3a97786975173e0889607dfd 1 parent 8960b12
@rabidgremlin rabidgremlin authored
Showing with 105 additions and 29 deletions.
  1. +101 −29 src/OSCeleton.cpp
  2. +4 −0 src/OSCeleton.vcxproj.user
View
130 src/OSCeleton.cpp
@@ -33,13 +33,17 @@
char *ADDRESS = "127.0.0.1";
int PORT = 7110;
-#define OUTPUT_BUFFER_SIZE 1024
+#define OUTPUT_BUFFER_SIZE 1024*16
char osc_buffer[OUTPUT_BUFFER_SIZE];
UdpTransmitSocket *transmitSocket;
char tmp[50]; //Temp buffer for OSC address pattern
int userID;
float jointCoords[3];
+float jointOrients[9];
+
+float posConfidence;
+float orientConfidence;
//Multipliers for coordinate system. This is useful if you use
//software like animata, that needs OSC messages to use an arbitrary
@@ -63,6 +67,7 @@ bool sendRot = false;
bool filter = false;
bool preview = false;
bool raw = false;
+bool sendOrient = false;
int nDimensions = 3;
void (*oscFunc)(osc::OutboundPacketStream*, char*) = NULL;
@@ -150,30 +155,38 @@ void XN_CALLBACK_TYPE calibration_ended(xn::SkeletonCapability& capability, XnUs
-int jointPos(XnUserID player, XnSkeletonJoint eJoint) {
- XnSkeletonJointPosition joint;
- userGenerator.GetSkeletonCap().GetSkeletonJointPosition(player, eJoint, joint);
+int jointPos(XnUserID player, XnSkeletonJoint eJoint) {
+
+ XnSkeletonJointTransformation jointTrans;
- if (joint.fConfidence < 0.5)
- return -1;
+ userGenerator.GetSkeletonCap().GetSkeletonJoint(player, eJoint, jointTrans);
+ posConfidence = jointTrans.position.fConfidence;
+
userID = player;
if (!raw)
{
- jointCoords[0] = off_x + (mult_x * (1280 - joint.position.X) / 2560); //Normalize coords to 0..1 interval
- jointCoords[1] = off_y + (mult_y * (960 - joint.position.Y) / 1920); //Normalize coords to 0..1 interval
- jointCoords[2] = off_z + (mult_z * joint.position.Z * 7.8125 / 10000); //Normalize coords to 0..7.8125 interval
+ jointCoords[0] = off_x + (mult_x * (1280 - jointTrans.position.position.X) / 2560); //Normalize coords to 0..1 interval
+ jointCoords[1] = off_y + (mult_y * (960 - jointTrans.position.position.Y) / 1920); //Normalize coords to 0..1 interval
+ jointCoords[2] = off_z + (mult_z * jointTrans.position.position.Z * 7.8125 / 10000); //Normalize coords to 0..7.8125 interval
}
else
{
- jointCoords[0] = joint.position.X;
- jointCoords[1] = joint.position.Y;
- jointCoords[2] = joint.position.Z;
+ jointCoords[0] = jointTrans.position.position.X;
+ jointCoords[1] = jointTrans.position.position.Y;
+ jointCoords[2] = jointTrans.position.position.Z;
}
-//for (int i=0; i<9; i++)
- // jointRots[i] = joint.orientation.orientation.elements[i];
+ if (sendOrient)
+ {
+ orientConfidence = jointTrans.orientation.fConfidence;
+
+ for (int i=0; i<9; i++)
+ {
+ jointOrients[i] = jointTrans.orientation.orientation.elements[i];
+ }
+ }
return 0;
}
@@ -182,26 +195,80 @@ int jointPos(XnUserID player, XnSkeletonJoint eJoint) {
// Generate OSC message with default format
void genOscMsg(osc::OutboundPacketStream *p, char *name) {
- *p << osc::BeginMessage( "/joint" );
- *p << name;
- if (!kitchenMode)
- *p << userID;
- for (int i = 0; i < nDimensions; i++)
- *p << jointCoords[i];
- //for (int i=0; i < 9; i++)
- // *p << (float)jointRots[i];
- *p << osc::EndMessage;
+
+ if (posConfidence >= 0.5f)
+ {
+ *p << osc::BeginMessage( "/joint" );
+ *p << name;
+ if (!kitchenMode)
+ *p << userID;
+ for (int i = 0; i < nDimensions; i++)
+ *p << jointCoords[i];
+ *p << osc::EndMessage;
+ }
+
+ if (!kitchenMode && sendOrient && orientConfidence >= 0.5f)
+ {
+ *p << osc::BeginMessage( "/orient" );
+ *p << name;
+ if (!kitchenMode)
+ *p << userID;
+
+ // x data is in first column
+ *p << jointOrients[0];
+ *p << jointOrients[0+3];
+ *p << jointOrients[0+6];
+
+ // y data is in 2nd column
+ *p << jointOrients[1];
+ *p << jointOrients[1+3];
+ *p << jointOrients[1+6];
+
+ // z data is in 3rd column
+ *p << jointOrients[2];
+ *p << jointOrients[2+3];
+ *p << jointOrients[2+6];
+
+ *p << osc::EndMessage;
+ }
}
// Generate OSC message with Quartz Composer format - based on Steve Elbows's code ;)
void genQCMsg(osc::OutboundPacketStream *p, char *name) {
- sprintf(tmp, "/joint/%s/%d", name, userID);
- *p << osc::BeginMessage(tmp);
- for (int i = 0; i < nDimensions; i++)
- *p << jointCoords[i];
- *p << osc::EndMessage;
+
+ if (posConfidence >= 0.5f)
+ {
+ sprintf(tmp, "/joint/%s/%d", name, userID);
+ *p << osc::BeginMessage(tmp);
+ for (int i = 0; i < nDimensions; i++)
+ *p << jointCoords[i];
+ *p << osc::EndMessage;
+ }
+
+ if (sendOrient && orientConfidence >= 0.5f)
+ {
+ sprintf(tmp, "/orient/%s/%d", name, userID);
+ *p << osc::BeginMessage(tmp);
+
+ // x data is in first column
+ *p << jointOrients[0];
+ *p << jointOrients[0+3];
+ *p << jointOrients[0+6];
+
+ // y data is in 2nd column
+ *p << jointOrients[1];
+ *p << jointOrients[1+3];
+ *p << jointOrients[1+6];
+
+ // z data is in 3rd column
+ *p << jointOrients[2];
+ *p << jointOrients[2+3];
+ *p << jointOrients[2+6];
+
+ *p << osc::EndMessage;
+ }
}
@@ -351,7 +418,8 @@ Options:\n\
-s <file>\t Save to file (only .oni supported at the moment).\n\
-i <file>\t Play from file (only .oni supported at the moment).\n\
-xr\t\tOutput raw kinect data\n\
- -xd\t\tTurn on puppet defaults: -xr -q -w\n\
+ -xt\t\tOutput joint orientation data\n\
+ -xd\t\tTurn on puppet defaults: -xr -xt -q -w\n\
-h\t\t Show help.\n\n\
For a more detailed explanation of options consult the README file.\n\n",
name, name);
@@ -518,9 +586,13 @@ int main(int argc, char **argv) {
case 'r': // turn on raw mode
raw = true;
break;
+ case 't': // send joint orientations
+ sendOrient = true;
+ break;
case 'd': // turn on default options
raw = true;
preview = true;
+ sendOrient = true;
oscFunc = &genQCMsg;
break;
default:
View
4 src/OSCeleton.vcxproj.user
@@ -1,3 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <LocalDebuggerCommandArguments>-xd</LocalDebuggerCommandArguments>
+ <DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
+ </PropertyGroup>
</Project>
Please sign in to comment.
Something went wrong with that request. Please try again.