Saturday, June 21, 2014

Getting Started With Kinect.v2 and Cinder, pt. 1: Cinder-Kinect2


...Gentlefolks, start your frameworks.

    So, I'm somewhat ashamed to admit this, but I've actually had my Kinect v2 devkit for about a month-and-a-half now and haven't really done much with it other than run some of the demos, browse the sample code, and in general be amazed at the technology.  Thank god for eyeo festival and time off for a week to just create and be inspired, as it allowed me to really get hands on with the hardware and some of the solutions available for Cinder.  Let's take a look, then, shall we?  In this first installment, we'll go over Cinder-Kinect2, which is a wrapper around the core SDK, developed by Stephen Schieberl of Wieden-Kennedy and of course, Cinder, fame.


DISCLAIMER: This is preliminary software and/or hardware and APIs are preliminary and subject to change

    Let me preface this by saying I'm not presenting anything show-stopping here, this isn't even Cinder Kinect 101 (it's more like 90), chances are most users probably know this stuff already, but at least it's here for some amount of posterity, and I will be updating this as the APIs mature (which I guess should be any week now?).

    Ok, that all said, here we go, for real.  Cinder-Kinect2 is the simpler of the two solutions, granted, they're both simple, Cinder-Kinect2 just requires less to get started.  How simple?  Well, assuming you have the K4W DPP SDK installed...

-> Clone or fork Ian Smith-Heisters' fork of Cinder-Kinect2, as it includes some fixes to account for changes in the 1404 Developer Preview SDK.

-> "Install" it as you would any ordinary Cinder block, i.e. clone your chosen repo into your <cinder_root>\blocks folder.

-> Pop open a sample, make whatever changes you need, if any, to the Project Properties.

-> Build and Run. ??? Profit!

    As of this writing, the main fork of Cinder-Kinect2 doesn't take the 1404 changes into account.  If you're interested in fixing it yourself, really you just need to make some minor changes involving the commenting out or removal to references to KinectStatus, as it's been deprecated, replacement pending, but the good Mr. Heisters has also added a few other features that make his branch worth taking a look at.

    The interface itself is as simple, if not simpler, than the installation process.  Here's a sample image and a snippet of the code that produced it, cribbed from the BasicApp and BodyApp sample:


void K2TutorialApp::update()
{
  if(mKinect->getFrame().getTimeStamp()>mFrame.getTimeStamp())
  {
    mFrame = mKinect->getFrame();
    if(mFrame.getColor())
    {
      mRgbTexture = gl::Texture(mFrame.getColor());
      auto cBodies = mFrame.getBodies();
      if(cBodies.size()>0)
        mJoints = cBodies.at(0).getJointMap();
    }
  }
}

void K2TutorialApp::draw()
{
  gl::clear(Color(0, 0, 0));
  if(mFrame.getColor())
  {
    mRgbTex = gl::Texture::create(mFrame.getColor());
    gl::draw(mRgbTex,
          Rectf(Vec2f::zero(), getWindowSize()));

    auto cJoints = mBody.getJointMap();
    if(cJoints.size()>0)
    {
      gl::pushMatrices();
      gl::scale(Vec2f(getWindowSize()) / Vec2f(mRgbTex->getSize()));
      for(auto cCjoint : cJoints)
      {
        Vec2f cp = Kinect2::mapBodyCoordToColor(
                cCjoint.second.getPosition(),
                mKinect->getCoordinateMapper());
        gl::drawSolidCircle(cp,10);
      }
      gl::popMatrices();
    }
  }
}

Resources

No comments:

Post a Comment