public synchronized void paint(Graphics g) { if (mLastFrame == null) { return; } int framePosX = 0; int framePosY = 0; VideoFrameRef depthFrame = mLastFrame.getDepthFrame(); if (depthFrame != null) { int width = depthFrame.getWidth(); int height = depthFrame.getHeight(); // make sure we have enough room if (mBufferedImage == null || mBufferedImage.getWidth() != width || mBufferedImage.getHeight() != height) { mBufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); } mBufferedImage.setRGB(0, 0, width, height, mDepthPixels, 0, width); framePosX = (getWidth() - width) / 2; framePosY = (getHeight() - height) / 2; g.drawImage(mBufferedImage, framePosX, framePosY, null); } for (UserData user : mLastFrame.getUsers()) { if (user.getSkeleton().getState() == SkeletonState.TRACKED) { drawLimb(g, framePosX, framePosY, user, JointType.HEAD, JointType.NECK); drawLimb(g, framePosX, framePosY, user, JointType.LEFT_SHOULDER, JointType.LEFT_ELBOW); drawLimb(g, framePosX, framePosY, user, JointType.LEFT_ELBOW, JointType.LEFT_HAND); drawLimb(g, framePosX, framePosY, user, JointType.RIGHT_SHOULDER, JointType.RIGHT_ELBOW); drawLimb(g, framePosX, framePosY, user, JointType.RIGHT_ELBOW, JointType.RIGHT_HAND); drawLimb(g, framePosX, framePosY, user, JointType.LEFT_SHOULDER, JointType.RIGHT_SHOULDER); drawLimb(g, framePosX, framePosY, user, JointType.LEFT_SHOULDER, JointType.TORSO); drawLimb(g, framePosX, framePosY, user, JointType.RIGHT_SHOULDER, JointType.TORSO); drawLimb(g, framePosX, framePosY, user, JointType.LEFT_HIP, JointType.TORSO); drawLimb(g, framePosX, framePosY, user, JointType.RIGHT_HIP, JointType.TORSO); drawLimb(g, framePosX, framePosY, user, JointType.LEFT_HIP, JointType.RIGHT_HIP); drawLimb(g, framePosX, framePosY, user, JointType.LEFT_HIP, JointType.LEFT_KNEE); drawLimb(g, framePosX, framePosY, user, JointType.LEFT_KNEE, JointType.LEFT_FOOT); drawLimb(g, framePosX, framePosY, user, JointType.RIGHT_HIP, JointType.RIGHT_KNEE); drawLimb(g, framePosX, framePosY, user, JointType.RIGHT_KNEE, JointType.RIGHT_FOOT); } } }
public synchronized void paint(Graphics g) { if (mLastFrame == null) { return; } int framePosX = 0; int framePosY = 0; VideoFrameRef depthFrame = mLastFrame.getDepthFrame(); if (depthFrame != null) { int width = depthFrame.getWidth(); int height = depthFrame.getHeight(); // make sure we have enough room if (mBufferedImage == null || mBufferedImage.getWidth() != width || mBufferedImage.getHeight() != height) { mBufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); } mBufferedImage.setRGB(0, 0, width, height, mDepthPixels, 0, width); framePosX = (getWidth() - width) / 2; framePosY = (getHeight() - height) / 2; g.drawImage(mBufferedImage, framePosX, framePosY, null); } for (UserData user : mLastFrame.getUsers()) { if (user.getSkeleton().getState() == SkeletonState.TRACKED) { drawSkeleton(g, framePosX, framePosY, user); // spatial joint's coordinates // giveMeSpatialCoordinateJoints(user); try { createSkeletonInstances(user); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } if (user.getSkeleton().getState() == SkeletonState.TRACKED && startedTest) { try { createSkeletonInstances(user); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } // System.out.println("send"); } } }
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(); }