コード例 #1
0
 void run() {
   while (shouldRun) {
     viewer.updateDepth();
     if (!viewer.isDrawRGB()) {
       viewer.updateIR();
     }
     viewer.repaint();
   }
   frame.dispose();
 }
コード例 #2
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();
  }
コード例 #3
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());
  }
コード例 #4
0
    @Override
    public void propertyChange(PropertyChangeEvent e) {
      int threshold = 40;
      int histIntensity = Integer.parseInt(e.getNewValue().toString());

      // check if the value is within the threshold long enough and change to IR if needed
      if (histIntensity < threshold) {
        darkHistCounter++;
        if (darkHistCounter > 300) {
          viewer.setDrawRGB(false);
          darkHistCounter = 0;
        }
      }
    }
コード例 #5
0
 public UserViewer(UserTracker tracker) {
   mTracker = tracker;
   mTracker.addNewFrameListener(this);
   mColors = new int[] {0xFFFF0000, 0xFF00FF00, 0xFF0000FF, 0xFFFFFF00, 0xFFFF00FF, 0xFF00FFFF};
 }
コード例 #6
0
 @Override
 public void propertyChange(PropertyChangeEvent e) {
   // set the presence of a person to force the face detection
   viewer.setMustFind(Boolean.parseBoolean(e.getNewValue().toString()));
 }
コード例 #7
0
 public void remove() {
   mTracker.removeNewFrameListener(this);
 }
コード例 #8
0
 public void init() {
   mTracker.addNewFrameListener(this);
   mColors = new int[] {0xFFFF0000, 0xFF00FF00, 0xFF0000FF, 0xFFFFFF00, 0xFFFF00FF, 0xFF00FFFF};
 }