Esempio n. 1
0
  public synchronized void onNewFrame(UserTracker tracker) {
    if (mLastFrame != null) {
      mLastFrame.release();
      mLastFrame = null;
    }

    mLastFrame = mTracker.readFrame();

    // check if any new user detected
    for (UserData user : mLastFrame.getUsers()) {
      if (user.isNew()) {
        // start skeleton tracking
        mTracker.startSkeletonTracking(user.getId());
      }
    }

    VideoFrameRef depthFrame = mLastFrame.getDepthFrame();

    if (depthFrame != null) {
      ByteBuffer frameData = depthFrame.getData().order(ByteOrder.LITTLE_ENDIAN);
      ByteBuffer usersFrame = mLastFrame.getUserMap().getPixels().order(ByteOrder.LITTLE_ENDIAN);

      // make sure we have enough room
      if (mDepthPixels == null
          || mDepthPixels.length < depthFrame.getWidth() * depthFrame.getHeight()) {
        mDepthPixels = new int[depthFrame.getWidth() * depthFrame.getHeight()];
      }

      calcHist(frameData);
      frameData.rewind();

      int pos = 0;
      while (frameData.remaining() > 0) {
        short depth = frameData.getShort();
        short userId = usersFrame.getShort();
        short pixel = (short) mHistogram[depth];
        int color = 0xFFFFFFFF;
        if (userId > 0) {
          color = mColors[userId % mColors.length];
        }

        mDepthPixels[pos] = color & (0xFF000000 | (pixel << 16) | (pixel << 8) | pixel);
        pos++;
      }
    }

    repaint();
  }
Esempio n. 2
0
  private void drawLimb(Graphics g, int x, int y, UserData user, JointType from, JointType to) {
    com.primesense.nite.SkeletonJoint fromJoint = user.getSkeleton().getJoint(from);
    com.primesense.nite.SkeletonJoint toJoint = user.getSkeleton().getJoint(to);

    if (fromJoint.getPositionConfidence() == 0.0 || toJoint.getPositionConfidence() == 0.0) {
      return;
    }

    com.primesense.nite.Point2D<Float> fromPos =
        mTracker.convertJointCoordinatesToDepth(fromJoint.getPosition());
    com.primesense.nite.Point2D<Float> toPos =
        mTracker.convertJointCoordinatesToDepth(toJoint.getPosition());

    // draw it in another color than the use color
    g.setColor(new Color(mColors[(user.getId() + 1) % mColors.length]));
    g.drawLine(
        x + fromPos.getX().intValue(),
        y + fromPos.getY().intValue(),
        x + toPos.getX().intValue(),
        y + toPos.getY().intValue());
  }
Esempio n. 3
0
 public UserViewer(UserTracker tracker) {
   mTracker = tracker;
   mTracker.addNewFrameListener(this);
   mColors = new int[] {0xFFFF0000, 0xFF00FF00, 0xFF0000FF, 0xFFFFFF00, 0xFFFF00FF, 0xFF00FFFF};
 }
 public void remove() {
   mTracker.removeNewFrameListener(this);
 }
 public void init() {
   mTracker.addNewFrameListener(this);
   mColors = new int[] {0xFFFF0000, 0xFF00FF00, 0xFF0000FF, 0xFFFFFF00, 0xFFFF00FF, 0xFF00FFFF};
 }