Skip to content
Browse files

Update to the new version of SKJ

Now more skellie, less pythonic. Not pythonic at all, actually. Oh well.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
  • Loading branch information...
1 parent 4fdc045 commit 7ef6f705a49fb9f930eb1e2bf957cd2d9c98537a @vmg committed Feb 4, 2011
Showing with 219 additions and 430 deletions.
  1. +80 −145 examples/position/main.cpp
  2. +0 −34 setup.py
  3. +84 −112 src/skeletonjelly.cpp
  4. +40 −53 src/skeletonjelly.hpp
  5. +2 −4 src/test_main.cpp
  6. +0 −11 swig/skeletonjelly.i
  7. +0 −71 swig/skeletonjelly_py.i
  8. BIN waf
  9. +13 −0 wscript
View
225 examples/position/main.cpp
@@ -1,6 +1,6 @@
#include <list>
-#include "GL/glut.h"
-#include "Gl/gl.h"
+#include "GLUT/glut.h"
+#include "OpenGL/gl.h"
#include "../../src/skeletonjelly.hpp"
#define WINDOW_X 800
@@ -18,21 +18,10 @@ Kinect g_kinect;
char g_message[64] = {0};
char g_coords[64] = {0};
+char g_leftHand[64] = {0};
+char g_rightHand[64] = {0};
-const Kinect_UserData *g_userData = NULL;
-
-#define TRACE_LENGTH 16
-std::list<XnPoint3D> g_traceLeft;
-std::list<XnPoint3D> g_traceRight;
-
-enum Scene
-{
- SCENE_POSITION = 0,
- SCENE_ARMS,
- SCENE_MAX
-};
-
-Scene g_drawScene = SCENE_POSITION;
+const KinectUser *g_userData = NULL;
static const char *MESSAGES[] =
{
@@ -46,7 +35,7 @@ static const char *MESSAGES[] =
void kinect_status(Kinect *k, Kinect::CallbackType cb_type, XnUserID id, void *data)
{
- sprintf_s(g_message, 64, "User [%d]: %s", id, MESSAGES[cb_type]);
+ snprintf(g_message, 64, "User [%d]: %s", id, MESSAGES[cb_type]);
printf("%s\n", g_message);
if (cb_type == Kinect::CB_NEW_USER && id == 1)
@@ -65,74 +54,16 @@ void glPrintString(void *font, char *str)
}
}
-void drawPosition()
+void drawTracking()
{
- glOrtho(-ROOM_X / 2.0f, +ROOM_X / 2.0f, ROOM_Y, 0.0f, -1.0, 1.0);
- glColor3f(1.0f, 1.0f, 1.0f);
- glLineWidth(1.0f);
-
- glBegin(GL_LINES);
-
- float x;
-
- int rows = (ROOM_Y) / GRID_SIZE;
- x = 0.0f;
- for (int i = 0; i < rows; ++i)
- {
- if (i & 1)
- glColor4f(0.65, 0.65, 0.65, 0.5);
- else
- glColor3f(1.0f, 1.0f, 1.0f);
-
- glVertex2f(-ROOM_X, x);
- glVertex2f(+ROOM_Y, x);
- x += GRID_SIZE;
- }
-
- int cols = (ROOM_X) / GRID_SIZE;
- x = -ROOM_X / 2;
- for (int i = 0; i < cols; ++i)
- {
- if (i & 1)
- glColor4f(0.65, 0.65, 0.65, 0.5);
- else
- glColor3f(1.0f, 1.0f, 1.0f);
-
- glVertex2f(x, 0.0f);
- glVertex2f(x, +ROOM_Y);
- x += GRID_SIZE;
- }
+ glOrtho(0, 1.0, 1.0, 0.0f, -1.0, 1.0);
- glEnd();
-
- glColor3f(0.33, 0.33, 0.33);
- glTranslatef(0.0f, 0.0f, 0.0f);
- glutSolidSphere(0.2f, 16, 4);
+ glPointSize(16.0f);
+ glLineWidth(8.0f);
if (g_userData)
{
- const XnPoint3D *p = &g_userData->world.centerOfMass;
-
- glTranslatef(SCALE(p->X), SCALE(p->Z), 0.0f);
-
- glColor3f(0.66, 0.33, 0.33);
- if (g_userData->status & Kinect::USER_TRACKING)
- glColor3f(0.33, 0.66, 0.33);
-
- glutSolidSphere(0.1f, 16, 4);
- sprintf_s(g_coords, 64, "(%0.4f, %0.4f, %0.4f)\n", p->X, p->Y, p->Z);
- }
-}
-
-void drawArms()
-{
- XnUInt32XYPair resolution = g_kinect.getDepthResolution();
- glOrtho(0, resolution.X, resolution.Y, 0.0f, -1.0, 1.0);
- glPointSize(8.0f);
-
- if (g_userData)
- {
- const XnPoint3D *com = &g_userData->screen.centerOfMass;
+ const XnPoint3D *com = &g_userData->centerOfMass;
glColor3f(0.66, 0.33, 0.33);
if (g_userData->status & Kinect::USER_TRACKING)
@@ -142,58 +73,66 @@ void drawArms()
glVertex3f(com->X, com->Y, 0.1f);
glEnd();
- sprintf_s(g_coords, 64, "(%0.4f, %0.4f, %0.4f)\n", com->X, com->Y, com->Z);
+ snprintf(g_coords, 64, "CoM: (%0.4f, %0.4f, %0.4f)\n", com->X, com->Y, com->Z);
if (g_kinect.userStatus() & Kinect::USER_TRACKING)
{
- const XnPoint3D *joints = g_userData->screen.joints;
- const XnPoint3D *leftHand = &g_userData->screen.joints[XN_SKEL_LEFT_HAND];
- const XnPoint3D *rightHand = &g_userData->screen.joints[XN_SKEL_RIGHT_HAND];
-
- glColor3f(1.0f, 1.0f, 1.0f);
- glLineWidth(8.0f);
- glBegin(GL_LINES);
- glVertex3f(joints[XN_SKEL_LEFT_SHOULDER].X, joints[XN_SKEL_LEFT_SHOULDER].Y, 0.1f);
- glVertex3f(joints[XN_SKEL_LEFT_ELBOW].X, joints[XN_SKEL_LEFT_ELBOW].Y, 0.1f);
-
- glVertex3f(joints[XN_SKEL_LEFT_ELBOW].X, joints[XN_SKEL_LEFT_ELBOW].Y, 0.1f);
- glVertex3f(joints[XN_SKEL_LEFT_HAND].X, joints[XN_SKEL_LEFT_HAND].Y, 0.1f);
-
+ const KinectUser::Hand *left = &g_userData->left;
+ const KinectUser::Hand *right = &g_userData->right;
- glVertex3f(joints[XN_SKEL_RIGHT_SHOULDER].X, joints[XN_SKEL_RIGHT_SHOULDER].Y, 0.1f);
- glVertex3f(joints[XN_SKEL_RIGHT_ELBOW].X, joints[XN_SKEL_RIGHT_ELBOW].Y, 0.1f);
-
- glVertex3f(joints[XN_SKEL_RIGHT_ELBOW].X, joints[XN_SKEL_RIGHT_ELBOW].Y, 0.1f);
- glVertex3f(joints[XN_SKEL_RIGHT_HAND].X, joints[XN_SKEL_RIGHT_HAND].Y, 0.1f);
- glEnd();
-
- if (g_traceLeft.empty() || g_traceLeft.back().X != leftHand->X || g_traceLeft.back().Y != leftHand->Y)
+ if (left->tracked)
{
- g_traceLeft.push_back(*leftHand);
- if (g_traceLeft.size() > TRACE_LENGTH)
- g_traceLeft.pop_front();
+ snprintf(g_leftHand, 64, "Left: (%0.4f, %0.4f, %s) %f %s\n",
+ left->pos.X, left->pos.Y,
+ left->pos.Z >= 0.8f ? "PUSH" : "-",
+ left->variance,
+ left->variance <= 0.1f ? "IDLE" : "");
+
+ glColor3f(1.0f, 1.0f, 1.0f);
+ glBegin(GL_POINTS);
+ glVertex3f(left->pos.X, left->pos.Y, 0.1f);
+ glEnd();
+
+ glColor4f(0.81, 0.72, 0.66, 0.33);
+ glLineWidth(4.0f);
+ std::list<XnPoint3D>::const_iterator it;
+
+ glBegin(GL_LINE_STRIP);
+ for (it = left->history.begin(); it != left->history.end(); ++it)
+ glVertex3f((*it).X, (*it).Y, 0.1f);
+ glEnd();
}
-
- if (g_traceRight.empty() || g_traceRight.back().X != rightHand->X || g_traceRight.back().Y != rightHand->Y)
+ else
{
- g_traceRight.push_back(*rightHand);
- if (g_traceRight.size() > TRACE_LENGTH)
- g_traceRight.pop_front();
+ snprintf(g_leftHand, 64, "Left: --");
+ }
+
+ if (right->tracked)
+ {
+ snprintf(g_rightHand, 64, "Right: (%0.4f, %0.4f, %s) %f %s\n",
+ right->pos.X, right->pos.Y,
+ right->pos.Z >= 0.8f ? "PUSH" : "-",
+ right->variance,
+ right->variance <= 0.1f ? "IDLE" : "");
+
+ glColor3f(1.0f, 1.0f, 1.0f);
+ glBegin(GL_POINTS);
+ glVertex3f(right->pos.X, right->pos.Y, 0.1f);
+ glEnd();
+
+ glColor4f(0.81, 0.72, 0.66, 0.33);
+ glLineWidth(4.0f);
+ std::list<XnPoint3D>::const_iterator it;
+
+ glBegin(GL_LINE_STRIP);
+ for (it = right->history.begin(); it != right->history.end(); ++it)
+ glVertex3f((*it).X, (*it).Y, 0.1f);
+ glEnd();
+ }
+ else
+ {
+ snprintf(g_rightHand, 64, "Right: --");
}
-
- glColor4f(0.81, 0.72, 0.66, 0.33);
- glLineWidth(4.0f);
- std::list<XnPoint3D>::iterator it;
-
- glBegin(GL_LINE_STRIP);
- for (it = g_traceLeft.begin(); it != g_traceLeft.end(); ++it)
- glVertex3f((*it).X, (*it).Y, 0.1f);
- glEnd();
-
- glBegin(GL_LINE_STRIP);
- for (it = g_traceRight.begin(); it != g_traceRight.end(); ++it)
- glVertex3f((*it).X, (*it).Y, 0.1f);
- glEnd();
}
}
}
@@ -214,6 +153,12 @@ void drawHUD()
glRasterPos2i(10, 30);
glPrintString(GLUT_BITMAP_HELVETICA_18, g_coords);
+ glRasterPos2i(10, 50);
+ glPrintString(GLUT_BITMAP_HELVETICA_18, g_leftHand);
+
+ glRasterPos2i(10, 70);
+ glPrintString(GLUT_BITMAP_HELVETICA_18, g_rightHand);
+
glEnable(GL_DEPTH_TEST);
glPopMatrix();
}
@@ -233,28 +178,22 @@ void glutDisplay()
glDisable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- switch (g_drawScene)
- {
- case SCENE_POSITION:
- drawPosition();
- break;
-
- case SCENE_ARMS:
- drawArms();
- break;
-
- default:
- break;
- }
-
+ drawTracking();
drawHUD();
glutSwapBuffers();
}
void glutIdle()
{
+ static int time = 0;
+
+ int now = glutGet(GLUT_ELAPSED_TIME);
+
+ g_kinect.tick(now - time);
glutPostRedisplay();
+
+ time = now;
}
void glutKeyboard (unsigned char key, int x, int y)
@@ -263,19 +202,15 @@ void glutKeyboard (unsigned char key, int x, int y)
{
case 27:
exit(0);
-
- case ' ':
- g_drawScene = (Scene)(((int)g_drawScene + 1) % (int)SCENE_MAX);
- break;
}
}
void glInit (int *pargc, char **argv)
{
glutInit(pargc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(WINDOW_X, WINDOW_Y);
- glutCreateWindow ("Positioning Sample");
- //glutFullScreen();
+ glutCreateWindow ("SkeletonJelly Debug");
+ glutFullScreen();
glutSetCursor(GLUT_CURSOR_NONE);
glutKeyboardFunc(glutKeyboard);
@@ -294,8 +229,8 @@ void glInit (int *pargc, char **argv)
int main(int argc, char **argv)
{
g_kinect.setEventCallback(kinect_status, NULL);
+ g_kinect.setTicksPerSecond(30);
g_kinect.init();
- g_kinect.runThreaded();
glInit(&argc, argv);
glutMainLoop();
View
34 setup.py
@@ -1,34 +0,0 @@
-#!/usr/bin/env python
-
-"""
-SkeletonJelly setup file
-"""
-
-import os
-from distutils.core import setup, Extension
-
-try:
- OPENNI_LIB = os.environ['OPEN_NI_LIB']
- OPENNI_INC = os.environ['OPEN_NI_INCLUDE']
-except KeyError:
- OPENNI_LIB = '/usr/lib'
- OPENNI_INC = '/usr/include/ni'
-
-skj_mod = Extension('_skeletonjelly',
- sources=['src/skeletonjelly.cpp', 'swig/skeletonjelly.i'],
- include_dirs = [OPENNI_INC],
- library_dirs = [OPENNI_LIB],
- libraries = ['OpenNI'],
- language = 'c++',
- swig_opts=['-c++'],
- #extra_compile_args = ['/Zi', '/EHsc'],
- #extra_link_args = ['/DEBUG'],
-)
-
-setup(name = "skeletonjelly",
- version = "0.2",
- description = "Kinect Skeleton tracking for people with mild brain damage",
- ext_modules = [skj_mod],
- package_dir = {'' : 'swig'},
- py_modules = ["skeletonjelly"],
-)
View
196 src/skeletonjelly.cpp
@@ -48,18 +48,14 @@ Kinect::Kinect()
_eventCallback = 0;
_callbackData = 0;
-#ifdef _WIN32
- _thread = 0;
-#endif
+ _elapsed = 0;
for (unsigned int i = 0; i < MAX_USERS; ++i)
_userData[i] = 0;
}
Kinect::~Kinect()
{
- stopThread();
-
for (unsigned int i = 0; i < MAX_USERS; ++i)
delete _userData[i];
@@ -139,7 +135,8 @@ XnStatus Kinect::init(SensorMode depthMode, SensorMode imageMode)
_userGen.GetSkeletonCap().GetCalibrationPose(_calibrationPose);
}
- _userGen.GetSkeletonCap().SetSkeletonProfile(XN_SKEL_PROFILE_ALL);
+ /* TODO: XN_SKEL_PROFILE_HEAD_HANDS ? */
+ _userGen.GetSkeletonCap().SetSkeletonProfile(XN_SKEL_PROFILE_UPPER);
}
_error = _context.StartGeneratingAll();
@@ -150,24 +147,19 @@ XnStatus Kinect::init(SensorMode depthMode, SensorMode imageMode)
}
-void Kinect::tick()
+void Kinect::tick(int elapsed)
{
-#ifdef _WIN32
- int nextTick = GetTickCount() + _tickTime;
-#endif
-
- // putchar('t');
+ _elapsed += elapsed;
_context.WaitAndUpdateAll();
- for (unsigned int i = 1; i < MAX_USERS; ++i)
- if (userActive(i))
- updateUserData(i, _userData[i]);
+ if (_elapsed >= _tickTime)
+ {
+ for (unsigned int i = 1; i < MAX_USERS; ++i)
+ if (userActive(i))
+ updateUserData(i, _userData[i]);
-#ifdef _WIN32
- int sleep_time = nextTick - GetTickCount();
- if (sleep_time > 0)
- Sleep(sleep_time);
-#endif
+ _elapsed -= _tickTime;
+ }
}
XnStatus Kinect::resetUser(XnUserID id /*= DEFAULT_USER*/)
@@ -211,7 +203,7 @@ void Kinect::onNewUser(XnUserID id)
if (id < MAX_USERS)
{
if (_userData[id] == 0)
- _userData[id] = new Kinect_UserData;
+ _userData[id] = new KinectUser;
_userData[id]->status = USER_ACTIVE;
@@ -425,130 +417,110 @@ void Kinect::renderDepth(unsigned char *buffer, bool background, int pitch)
}
}
-void Kinect::updateUserData(XnUserID id, Kinect_UserData *data)
+void Kinect::processHand(KinectUser::Hand *hand, XnSkeletonJointPosition *jointWorld, float backPlane, float planeDepth, float xRes, float yRes)
{
- for (int i = 0; i < JOINT_COUNT; ++i)
- {
- _userGen.GetSkeletonCap().GetSkeletonJoint(id, (XnSkeletonJoint)i, data->world.joints[i]);
- memcpy(&data->screen.joints[i], &data->world.joints[i].position, sizeof(XnPoint3D));
- }
+ static const int max_history = 30;
+ static const int static_time_steps = 8;
- _depth.ConvertRealWorldToProjective(JOINT_COUNT, data->screen.joints, data->screen.joints);
+ _depth.ConvertRealWorldToProjective(1, &jointWorld->position, &hand->pos);
- _userGen.GetCoM(id, data->world.centerOfMass);
- _depth.ConvertRealWorldToProjective(1, &data->world.centerOfMass, &data->screen.centerOfMass);
-}
+ hand->pos.X /= xRes;
+ hand->pos.Y /= yRes;
+ hand->pos.Z = (backPlane - jointWorld->position.Z) / (planeDepth);
-int Kinect::userStatus(XnUserID id)
-{
- return userActive(id) ? _userData[id]->status : USER_INACTIVE;
-}
+ hand->tracked = jointWorld->fConfidence >= 0.5f;
-char const* Kinect::errorMessage()
-{
- return (_error != XN_STATUS_OK) ? xnGetStatusString(_error) : 0;
-}
+ hand->history.push_back(hand->pos);
+ if (hand->history.size() > max_history)
+ hand->history.pop_front();
-const XnPoint3D *Kinect::getJoint(int joint, bool projected, XnUserID id)
-{
- if (userActive(id))
+ if (hand->history.size() > static_time_steps)
{
- return projected ?
- &(_userData[id]->screen.joints[joint]) :
- &(_userData[id]->world.joints[joint].position.position);
- }
+ std::list<XnPoint3D>::reverse_iterator it;
+ float sumX = 0.0f, sumY = 0.0f, avgX, avgY, varX, varY;
+ int i;
- return 0;
-}
+ for (it = hand->history.rbegin(), i = 0;
+ i < static_time_steps; ++it, ++i)
+ {
+ sumX += (*it).X;
+ sumY += (*it).Y;
+ }
-const XnPoint3D *Kinect::getCoM(bool projected, XnUserID id)
-{
- if (userActive(id))
- {
- return projected ?
- &(_userData[id]->screen.centerOfMass) :
- &(_userData[id]->world.centerOfMass);
- }
+ avgX = sumX / static_time_steps;
+ avgY = sumY / static_time_steps;
+ sumX = 0.0f;
+ sumY = 0.0f;
+
+ for (it = hand->history.rbegin(), i = 0;
+ i < static_time_steps; ++it, ++i)
+ {
+ sumX += (avgX - (*it).X) * (avgX - (*it).X);
+ sumY += (avgY - (*it).Y) * (avgY - (*it).Y);
+ }
- return 0;
+ varX = sumX / (static_time_steps - 1.0f);
+ varY = sumY / (static_time_steps - 1.0f);
+
+ hand->variance = (varX + varY) * 1000.0f;
+ }
}
-const Kinect_UserData *Kinect::getUserData(XnUserID id /*= KINECT_DEFAULT_USER*/)
+void Kinect::updateUserData(XnUserID id, KinectUser *data)
{
- if (userActive(id))
+ static XnSkeletonJoint jointTranslation[] =
{
- return _userData[id];
- }
+ XN_SKEL_HEAD, /* JOINT_HEAD, */
+ XN_SKEL_LEFT_HAND, /* JOINT_HAND_LEFT, */
+ XN_SKEL_RIGHT_HAND, /* JOINT_HAND_RIGHT */
+ XN_SKEL_LEFT_ELBOW, /* JOINT_ELBOW_LEFT, */
+ XN_SKEL_RIGHT_ELBOW, /* JOINT_ELBOW_RIGHT, */
+ XN_SKEL_LEFT_SHOULDER, /* JOINT_SHOULDER_LEFT, */
+ XN_SKEL_RIGHT_SHOULDER, /* JOINT_SHOULDER_RIGHT, */
+ };
- return 0;
-}
+ static const float planeDepth = 500.0f;
-void Kinect::setEventCallback(Callback callback, void *userData)
-{
- _eventCallback = callback;
- _callbackData = userData;
-}
+ float backPlane, frontPlane;
+ XnUInt32XYPair resolution = getDepthResolution();
-void Kinect::setTicksPerSecond(int ticksPerSecond)
-{
- _tickTime = ticksPerSecond ? 1000 / ticksPerSecond : 0;
-}
+ if (data->status & USER_TRACKING)
+ {
+ for (int i = 0; i < KINECT_JOINT_MAX; ++i)
+ _userGen.GetSkeletonCap().GetSkeletonJointPosition(id, jointTranslation[i], data->joints[i]);
-#ifdef _WIN32
-DWORD WINAPI _Kinect_Thread(LPVOID ptr)
-{
- Kinect *k = (Kinect *)ptr;
- for (;;) k->tick();
- return 0;
-}
+ backPlane = (data->joints[JOINT_SHOULDER_LEFT].position.Z +
+ data->joints[JOINT_SHOULDER_RIGHT].position.Z) / 2.0f;
-XnStatus Kinect::runThreaded()
-{
- _thread = CreateThread(NULL, 0, _Kinect_Thread, (void *)this, 0, 0);
- return (_thread != 0) ? XN_STATUS_OK : XN_STATUS_OS_INVALID_THREAD;
-}
+ processHand(&data->left, &data->joints[JOINT_HAND_LEFT],
+ backPlane, planeDepth, (float)resolution.X, (float)resolution.Y);
-void Kinect::waitForThread(int timeout)
-{
- if (_thread != 0)
- {
- if (WaitForSingleObject(_thread, timeout) == 0)
- _thread = 0;
+ processHand(&data->right, &data->joints[JOINT_HAND_RIGHT],
+ backPlane, planeDepth, (float)resolution.X, (float)resolution.Y);
}
-}
-void Kinect::stopThread()
-{
- if (_thread != 0)
- {
- TerminateThread(_thread, 0);
- _thread = 0;
- }
-}
+ _userGen.GetCoM(id, data->centerOfMass);
+ _depth.ConvertRealWorldToProjective(1, &data->centerOfMass, &data->centerOfMass);
-bool Kinect::isThreaded()
-{
- return (_thread != 0);
-}
-#else
-XnStatus Kinect::runThreaded()
-{
- return XN_STATUS_ERROR;
+ data->centerOfMass.X /= (float)resolution.X;
+ data->centerOfMass.Y /= (float)resolution.Y;
}
-void Kinect::waitForThread(int timeout)
+char const* Kinect::errorMessage()
{
+ return (_error != XN_STATUS_OK) ? xnGetStatusString(_error) : 0;
}
-void Kinect::stopThread()
+void Kinect::setEventCallback(Callback callback, void *userData)
{
+ _eventCallback = callback;
+ _callbackData = userData;
}
-bool Kinect::isThreaded()
+void Kinect::setTicksPerSecond(int ticksPerSecond)
{
- return false;
+ _tickTime = ticksPerSecond ? 1000 / ticksPerSecond : 0;
}
-#endif
unsigned int Kinect::getImageTexSize(int pitch /*= 0*/)
{
View
93 src/skeletonjelly.hpp
@@ -1,57 +1,49 @@
#ifndef __IL_SKELETON_JELLY_H__
#define __IL_SKELETON_JELLY_H__
+#include <list>
+
#include <XnOpenNI.h>
#include <XnCodecIDs.h>
#include <XnCppWrapper.h>
-#if defined(JELLY_BUILD_DLL)
-# if defined(__GNUC__)
-# define DLL_PUBLIC __attribute__((dllexport))
-# elif defined(_MSC_VER)
-# define DLL_PUBLIC __declspec(dllexport)
-# else
-# define DLL_PUBLIC
-# endif
-#else
-# if defined(__GNUC__)
-# define DLL_PUBLIC __attribute__((dllimport))
-# elif defined(_MSC_VER)
-# define DLL_PUBLIC __declspec(dllimport)
-# else
-# define DLL_PUBLIC
-# endif
-#endif
-
#define KINECT_DEFAULT_USER 1
#define KINECT_DEFAULT_WIDTH 640
#define KINECT_DEFAULT_HEIGHT 480
#define KINECT_DEFAULT_FPS 30
+#define KINECT_JOINT_MAX 7
-#ifndef SWIG
-static const int JOINT_COUNT = 25;
-struct Kinect_UserData
+struct KinectUser
{
int status;
- struct
- {
- XnSkeletonJointTransformation joints[JOINT_COUNT];
- XnPoint3D centerOfMass;
- } world;
-
- struct
+ struct Hand
{
- XnPoint3D joints[JOINT_COUNT];
- XnPoint3D centerOfMass;
- } screen;
+ std::list<XnPoint3D> history;
+ XnPoint3D pos;
+ bool tracked;
+ float variance;
+ } left, right;
+
+ XnSkeletonJointPosition joints[KINECT_JOINT_MAX];
+ XnPoint3D centerOfMass;
};
-#endif
class Kinect
{
public:
+ enum Joints
+ {
+ JOINT_HEAD,
+ JOINT_HAND_LEFT,
+ JOINT_HAND_RIGHT,
+ JOINT_ELBOW_LEFT,
+ JOINT_ELBOW_RIGHT,
+ JOINT_SHOULDER_LEFT,
+ JOINT_SHOULDER_RIGHT
+ };
+
enum RenderFormat
{
RENDER_RGBA,
@@ -89,8 +81,6 @@ class Kinect
typedef void (*Callback)(Kinect*, CallbackType, XnUserID, void*);
-
-#ifndef SWIG
private:
static const int MAX_DEPTH = 4096;
static const int DEPTH_MASK = MAX_DEPTH - 1;
@@ -127,49 +117,44 @@ class Kinect
void onCalibrationStart(XnUserID nId);
void onCalibrationEnd(XnUserID nId, XnBool bSuccess);
- Kinect_UserData *_userData[MAX_USERS];
+ KinectUser *_userData[MAX_USERS];
- void updateUserData(XnUserID id, Kinect_UserData *data);
+ void updateUserData(XnUserID id, KinectUser *data);
+ void processHand(KinectUser::Hand *hand, XnSkeletonJointPosition *jointWorld, float backPlane, float planeDepth, float xRes, float yRes);
Callback _eventCallback;
void *_callbackData;
+ int _elapsed;
int _tickTime;
-# ifdef _WIN32
- HANDLE _thread;
-# endif
-
-#endif
-
public:
Kinect();
~Kinect();
void setTicksPerSecond(int ticksPerSecond);
- void tick();
-
- XnStatus runThreaded();
- void waitForThread(int timeout);
- void stopThread();
- bool isThreaded();
+ void tick(int elapsed);
XnStatus init(SensorMode depthSensor = SENSOR_VGA_30FPS, SensorMode imageSensor = SENSOR_DISABLED);
XnStatus resetUser(XnUserID id = KINECT_DEFAULT_USER);
XnStatus trackUser(XnUserID id = KINECT_DEFAULT_USER);
- int userStatus(XnUserID id = KINECT_DEFAULT_USER);
-
- const XnPoint3D *getJoint(int articulation, bool projected, XnUserID id = KINECT_DEFAULT_USER);
- const XnPoint3D *getCoM(bool projected, XnUserID id = KINECT_DEFAULT_USER);
- const Kinect_UserData *getUserData(XnUserID id = KINECT_DEFAULT_USER);
+ inline int userStatus(XnUserID id = KINECT_DEFAULT_USER)
+ {
+ return userActive(id) ? _userData[id]->status : USER_INACTIVE;
+ }
inline bool userActive(XnUserID id = KINECT_DEFAULT_USER)
{
return (id < MAX_USERS) && (_userData[id] != 0) && (_userData[id]->status != USER_INACTIVE);
}
+ inline const KinectUser *getUserData(XnUserID id)
+ {
+ return userActive(id) ? _userData[id] : 0;
+ }
+
void setEventCallback(Callback callback, void *userData);
char const* errorMessage();
@@ -185,4 +170,6 @@ class Kinect
void setRenderFormat(RenderFormat format);
};
+
+
#endif
View
6 src/test_main.cpp
@@ -1,9 +1,7 @@
-#include "kinect.hpp"
+#include "skeletonjelly.hpp"
int main(int argc, char *argv[])
{
- static const char *default_path = "C:/Program Files (x86)/OpenNI/Data/SamplesConfig.xml";
-
Kinect k;
XnMapOutputMode output = {640, 480, 30};
@@ -27,4 +25,4 @@ int main(int argc, char *argv[])
k.stopThread();
return (0);
-}
+}
View
11 swig/skeletonjelly.i
@@ -1,11 +0,0 @@
-%module skeletonjelly
-
-%{
- #include "../src/skeletonjelly.hpp"
-%}
-
-#ifdef SWIGPYTHON
- %include "skeletonjelly_py.i"
-#endif
-
-%include "../src/skeletonjelly.hpp"
View
71 swig/skeletonjelly_py.i
@@ -1,71 +0,0 @@
-%{
- void _pyKinectCallback(
- Kinect *kinect,
- Kinect::CallbackType t,
- XnUserID id,
- void *data)
- {
- PyObject *arglist;
- PyObject *result;
-
- PyGILState_STATE gstate;
-
- if (kinect->isThreaded())
- gstate = PyGILState_Ensure();
-
- arglist = Py_BuildValue("(ii)", t, id);
- result = PyObject_CallObject((PyObject *)data, arglist);
-
- Py_XDECREF(result);
- Py_DECREF(arglist);
-
- if (kinect->isThreaded())
- PyGILState_Release(gstate);
- }
-
-%}
-
-%typemap(in) unsigned char *buffer {
- PyObject *ctypes, *ptr;
- const char *method = "addressof";
- const char *arguments = "O";
-
- ctypes = PyImport_ImportModule("ctypes");
- ptr = PyObject_CallMethod(ctypes, (char *)method, (char *)arguments, $input);
- if (ptr == NULL)
- return NULL;
-
- $1 = (unsigned char *)PyInt_AsLong(ptr);
-
- Py_INCREF($input);
- Py_DECREF(ptr);
- Py_DECREF(ctypes);
-}
-
-%typemap(out) XnUInt32XYPair {
- $result = Py_BuildValue("(ii)", $1.X, $1.Y);
-}
-
-%typemap(out) XnPoint3D* {
- if ($1 == NULL) {
- $result = Py_BuildValue("");
- } else {
- $result = Py_BuildValue("(fff)", $1->X, $1->Y, $1->Z);
- }
-}
-
-%typemap(in) (Kinect::Callback callback, void *userData) {
- Py_INCREF($input);
- $1 = _pyKinectCallback;
- $2 = (void *)$input;
-}
-
-%typemap(out) XnStatus {
- if ($1 != XN_STATUS_OK) {
- PyErr_SetString(PyExc_RuntimeError, xnGetStatusString($1));
- return NULL;
- }
-
- $result = Py_BuildValue("");
-}
-
View
BIN waf
Binary file not shown.
View
13 wscript
@@ -0,0 +1,13 @@
+def options(opt):
+ opt.load('compiler_c++')
+
+def configure(conf):
+ conf.load('compiler_c++')
+ conf.env.FRAMEWORK = ['OpenGL', 'GLUT']
+
+def build(bld):
+ bld.program(source=['src/skeletonjelly.cpp', 'examples/position/main.cpp'],
+ lib = ['openni'],
+ libpath = ['/usr/lib'],
+ includes = ['src', '/usr/include/ni', 'examples/position'],
+ target='kinect_test')

0 comments on commit 7ef6f70

Please sign in to comment.
Something went wrong with that request. Please try again.